Example usage for org.opencv.video Video CamShift

List of usage examples for org.opencv.video Video CamShift

Introduction

In this page you can find the example usage for org.opencv.video Video CamShift.

Prototype

public static RotatedRect CamShift(Mat probImage, Rect window, TermCriteria criteria) 

Source Link

Usage

From source file:classes.ObjectFinder.java

private void computeTrackBox() {

    trackBox = new RotatedRect();

    if (computedSearchWindow.size().width > 0 && computedSearchWindow.size().height > 0
            && computedSearchWindow.area() > 1) {
        trackBox = Video.CamShift(thresholdedBackprojection, computedSearchWindow,
                new TermCriteria(2 | 1, 10, 1));
    }//from  w ww .  j av a2 s  .c o  m

    if (trackBox.size.width > 0 && trackBox.size.height > 0 && trackBox.size.area() > 1) {
        Core.ellipse(inputFrame, trackBox, new Scalar(0, 0, 255), 2);
    }

}

From source file:nz.ac.auckland.lablet.vision.CamShiftTracker.java

License:Open Source License

/**
 * Gets the location of an object in a frame. Assumes you have called setRegionOfInterest,
 * which informs CamShiftTracker which object to track.
 *
 * @param frame The frame to search for the object in.
 * @return The location and bounds of the object, represented by a Rect.
 *//*from   www .j ava  2s.c o  m*/
public Rect getObjectLocation(Bitmap frame) {
    Mat image = new Mat();
    Utils.bitmapToMat(frame, image);

    //        Mat out = new Mat(image.rows(), image.cols(), image.type());
    //        image.convertTo(out, -1, 2.0, 2.0);
    //        image = out;

    toHsv(image, hsvMin, hsvMax);

    ArrayList<Mat> hsvs = new ArrayList<>();
    hsvs.add(hsv);

    Imgproc.calcBackProject(hsvs, new MatOfInt(0), hist, backproj, ranges, 1);
    Core.bitwise_and(backproj, mask, backproj);

    try {
        Rect tempTrackWindow = trackWindow.clone();
        RotatedRect result = Video.CamShift(backproj, trackWindow, termCriteria);

        if (result.size.equals(new Size(0, 0)) && result.angle == 0 && result.center.equals(new Point(0, 0))) {
            trackWindow = tempTrackWindow;
            return null;
        }
    } catch (Exception e) {
        Log.e(TAG, "Shit went down: ", e);
        return null;
    }

    return trackWindow.clone();
}