Esempio n. 1
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;
  }