Example #1
0
  @Test
  public void initialLearning() {

    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);

    FastQueue<ImageRectangle> regions = new FastQueue<ImageRectangle>(ImageRectangle.class, true);
    regions.grow();
    regions.grow();
    regions.grow();

    alg.initialLearning(new RectangleCorner2D_F64(10, 20, 30, 40), regions);

    // Check to see if the variance threshold was set
    assertEquals(1, variance.calledSelect);
    // There should be a positive example
    assertEquals(1, fern.calledP);
    assertEquals(1, template.calledP);
    // several negative examples too
    assertEquals(3, fern.calledN);
    // only negative template for ambiguous, which there are none since I'm being lazy
    assertEquals(0, template.calledN);

    assertEquals(1, detection.calledDetection);
  }
Example #2
0
  /**
   * Starts tracking the rectangular region.
   *
   * @param image First image in the sequence.
   * @param x0 Top-left corner of rectangle. x-axis
   * @param y0 Top-left corner of rectangle. y-axis
   * @param x1 Bottom-right corner of rectangle. x-axis
   * @param y1 Bottom-right corner of rectangle. y-axis
   */
  public void initialize(T image, int x0, int y0, int x1, int y1) {

    if (imagePyramid == null
        || imagePyramid.getInputWidth() != image.width
        || imagePyramid.getInputHeight() != image.height) {
      int minSize = (config.trackerFeatureRadius * 2 + 1) * 5;
      int scales[] = selectPyramidScale(image.width, image.height, minSize);
      imagePyramid =
          FactoryPyramid.discreteGaussian(scales, -1, 1, true, (Class<T>) image.getClass());
    }
    imagePyramid.process(image);

    reacquiring = false;

    targetRegion.set(x0, y0, x1, y1);
    createCascadeRegion(image.width, image.height);

    template.reset();
    fern.reset();

    tracking.initialize(imagePyramid);
    variance.setImage(image);
    template.setImage(image);
    fern.setImage(image);
    adjustRegion.init(image.width, image.height);

    learning.initialLearning(targetRegion, cascadeRegions);
    strongMatch = true;
    previousTrackArea = targetRegion.area();
  }
Example #3
0
  /**
   * 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;
  }
Example #4
0
  @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);
  }