use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class TldRegionTracker method trackFeature.
/**
* Tracks KLT features in forward/reverse direction and the tracking error metrics
*/
protected boolean trackFeature() {
pairs.reset();
// total number of tracks which contribute to FB error
int numTracksFB = 0;
// tracks which are not dropped
int numTracksRemaining = 0;
for (int i = 0; i < tracks.length; i++) {
Track t = tracks[i];
if (!t.active)
continue;
float prevX = t.klt.x;
float prevY = t.klt.y;
// track in forwards direction
tracker.setImage(currentImage, currentDerivX, currentDerivY);
KltTrackFault result = tracker.track(t.klt);
if (result != KltTrackFault.SUCCESS) {
t.active = false;
continue;
}
float currX = t.klt.x;
float currY = t.klt.y;
// track in reverse direction
tracker.setDescription(t.klt);
tracker.setImage(previousImage, previousDerivX, previousDerivY);
result = tracker.track(t.klt);
if (result != KltTrackFault.SUCCESS) {
t.active = false;
continue;
}
// compute forward-backwards error
double errorForwardBackwards = UtilPoint2D_F32.distanceSq(prevX, prevY, t.klt.x, t.klt.y);
// put into lists for computing the median error
errorsFB[numTracksFB++] = errorForwardBackwards;
// discard if error is too large
if (errorForwardBackwards > maxErrorFB) {
t.active = false;
continue;
}
// create data structure used for group motion estimation
AssociatedPair p = pairs.grow();
p.p1.set(prevX, prevY);
p.p2.set(currX, currY);
numTracksRemaining++;
}
// if the forward-backwards error is too large, give up
double medianFB = QuickSelect.select(errorsFB, numTracksFB / 2, numTracksFB);
if (medianFB > maxErrorFB || numTracksRemaining < 4)
return false;
return true;
}
use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class QrCodeBinaryGridToPixel method set.
private void set(float row, float col, Polygon2D_F64 polygon, int corner) {
AssociatedPair p = storagePairs.grow();
Point2D_F64 c = polygon.get(corner);
p.set(c.x, c.y, col, row);
pairs.add(p);
}
use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class QrCodeBinaryGridToPixel method removeFeatureWithLargestError.
public boolean removeFeatureWithLargestError() {
int selected = -1;
double largestError = 0;
for (int i = 0; i < pairs.size(); i++) {
AssociatedPair p = pairs.get(i);
HomographyPointOps_F64.transform(Hinv, p.p2.x, p.p2.y, tmp64);
double dx = tmp64.x - p.p1.x;
double dy = tmp64.y - p.p1.y;
double error = dx * dx + dy * dy;
if (error > largestError) {
largestError = error;
selected = i;
}
}
if (selected != -1 && largestError > 2 * 2) {
pairs.remove(selected);
return true;
} else {
return false;
}
}
use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class TestDistanceScaleTranslate2DSq method perfect.
@Test
public void perfect() {
ScaleTranslate2D model = new ScaleTranslate2D(1.5, -2, 3);
AssociatedPair a = apply(-5, 4, model);
DistanceScaleTranslate2DSq alg = new DistanceScaleTranslate2DSq();
alg.setModel(model);
assertEquals(0, alg.computeDistance(a), 1e-8);
}
use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class TestDistanceScaleTranslate2DSq method noisy.
@Test
public void noisy() {
ScaleTranslate2D model = new ScaleTranslate2D(1.5, -2, 3);
AssociatedPair a = apply(-5, 4, model);
a.p2.x += 3.5;
DistanceScaleTranslate2DSq alg = new DistanceScaleTranslate2DSq();
alg.setModel(model);
assertEquals(3.5 * 3.5, alg.computeDistance(a), 1e-8);
}
Aggregations