Problems with object tracking

Hey all,

after successfully building OpenCV with contrib I ran into an error when trying to initialize a tracker. A smal example:

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;
import org.opencv.tracking.TrackerCSRT;
import org.opencv.tracking.TrackerKCF;
import org.opencv.video.Tracker;
import org.opencv.videoio.VideoCapture;

public class TrackTest {

    static {System.loadLibrary(Core.NATIVE_LIBRARY_NAME);}

    public static void main(String args[]) {

        Rect roi;
        Mat frame = new Mat();
        // create a tracker object
        Tracker tracker = TrackerCSRT.create();
        // set input video
        VideoCapture capture = new VideoCapture(0);
        capture.read(frame);
        // get bounding box
        roi= new Rect(310,230,20,20);


        // initialize the tracker
        tracker.init(frame,roi);

        while(true){
            capture.read(frame);
            tracker.update(frame,roi);

            Imgproc.rectangle(frame,roi,new Scalar(255,0,0));

            HighGui.imshow("Tracker",frame);
            HighGui.waitKey(1);


        }


    }


}

When running the program i recive the following error massage:

Exception in thread “main” java.lang.Exception: unknown exception
at org.opencv.video.Tracker.init_0(Native Method)
at org.opencv.video.Tracker.init(Tracker.java:33)
at View.TrackTest.main(TrackTest.java:32)

Maybe someone has an idea whats wrong. I also tried to build a try catch block but i could not retrieve anymore usefull information.

1 Like

opencv version ?

can you put a

System.out.println(frame);

before trying to initialize the tracker ?

1 Like

My opencv Version is 4.5.2

The Output of the println comand is:

Mat [ 480*640*CV_8UC3, isCont=true, isSubmat=false, nativeObj=0x188b4ab50f0, dataAddr=0x188bbcf5980 ]
1 Like

Facing an identic issue with org.opencv.video.TrackerMIL.TrackerMIL.create()
BTW I don’t see org.opencv.tracking package in the 4.5.2 release jar at all (./opencv/build/java/opencv-452.jar). Do I need to re-build it manually from the sources?

the tracking module lives in the contrib repo. you need a build that includes contrib modules… so yes probably you’ll have to build it yourself, unless you can find a built package with contrib.

1 Like