/** * Updates track region. * * @param image Next image in the sequence. * @return true if the object could be found and false if not */ public boolean track(T image) { boolean success = true; valid = false; imagePyramid.process(image); template.setImage(image); variance.setImage(image); fern.setImage(image); if (reacquiring) { // It can reinitialize if there is a single detection detection.detectionCascade(cascadeRegions); if (detection.isSuccess() && !detection.isAmbiguous()) { TldRegion region = detection.getBest(); reacquiring = false; valid = false; // set it to the detected region ImageRectangle r = region.rect; targetRegion.set(r.x0, r.y0, r.x1, r.y1); // get tracking running again tracking.initialize(imagePyramid); checkNewTrackStrong(region.confidence); } else { success = false; } } else { detection.detectionCascade(cascadeRegions); // update the previous track region using the tracker trackerRegion.set(targetRegion); boolean trackingWorked = tracking.process(imagePyramid, trackerRegion); trackingWorked &= adjustRegion.process(tracking.getPairs(), trackerRegion); TldHelperFunctions.convertRegion(trackerRegion, trackerRegion_I32); if (hypothesisFusion(trackingWorked, detection.isSuccess())) { // if it found a hypothesis and it is valid for learning, then learn if (valid && performLearning) { learning.updateLearning(targetRegion); } } else { reacquiring = true; success = false; } } if (strongMatch) { previousTrackArea = targetRegion.area(); } return success; }
@Test public void updateLearning() { DummyVariance variance = new DummyVariance(); DummyFern fern = new DummyFern(); DummyTemplate template = new DummyTemplate(); DummyDetection detection = new DummyDetection(); TldLearning alg = new TldLearning(rand, config, template, variance, fern, detection); alg.updateLearning(new RectangleCorner2D_F64(10, 20, 30, 40)); // Check to see if the variance threshold was set assertEquals(0, variance.calledSelect); // There should be a positive example assertEquals(1, fern.calledP); assertEquals(1, template.calledP); // several negative examples too assertEquals(10, fern.calledN); // only negative template for ambiguous, which there are none since I'm being lazy assertEquals(0, template.calledN); assertEquals(0, detection.calledDetection); }