Example #1
0
  /**
   * Combines hypotheses from tracking and detection.
   *
   * @param trackingWorked If the sequential tracker updated the track region successfully or not
   * @return true a hypothesis was found, false if it failed to find a hypothesis
   */
  protected boolean hypothesisFusion(boolean trackingWorked, boolean detectionWorked) {

    valid = false;

    boolean uniqueDetection = detectionWorked && !detection.isAmbiguous();
    TldRegion detectedRegion = detection.getBest();

    double confidenceTarget;

    if (trackingWorked) {

      // get the scores from tracking and detection
      double scoreTrack = template.computeConfidence(trackerRegion_I32);
      double scoreDetected = 0;

      if (uniqueDetection) {
        scoreDetected = detectedRegion.confidence;
      }

      double adjustment = strongMatch ? 0.07 : 0.02;

      if (uniqueDetection && scoreDetected > scoreTrack + adjustment) {
        // if there is a unique detection and it has higher confidence than the
        // track region, use the detected region
        TldHelperFunctions.convertRegion(detectedRegion.rect, targetRegion);
        confidenceTarget = detectedRegion.confidence;

        // if it's far away from the current track, re-evaluate if it's a strongMatch
        checkNewTrackStrong(scoreDetected);

      } else {
        // Otherwise use the tracker region
        targetRegion.set(trackerRegion);
        confidenceTarget = scoreTrack;

        strongMatch |= confidenceTarget > config.confidenceThresholdStrong;

        // see if the most likely detected region overlaps the track region
        if (strongMatch && confidenceTarget >= config.confidenceThresholdLower) {
          valid = true;
        }
      }
    } else if (uniqueDetection) {
      // just go with the best detected region
      detectedRegion = detection.getBest();
      TldHelperFunctions.convertRegion(detectedRegion.rect, targetRegion);
      confidenceTarget = detectedRegion.confidence;
      strongMatch = confidenceTarget > config.confidenceThresholdStrong;
    } else {
      return false;
    }

    return confidenceTarget >= config.confidenceAccept;
  }
Example #2
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;
  }