コード例 #1
0
ファイル: TldTracker.java プロジェクト: aleen42/BoofCV
  /**
   * 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();
  }
コード例 #2
0
ファイル: TldTracker.java プロジェクト: aleen42/BoofCV
  /**
   * 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;
  }