Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

videocapture reads the same frame differently on multiple calls

Hi, I am new to the forum. I have started using Opencv with Java a few weeks ago. In my program I use videocapture to read frames from an avi file. Yesterday I have noticed that, over different runs of my progrem, the n-th frame read from the file is different from the same n-th frame read from the same file, in a previous run. I have confirmed this by subtracting two copies of the same frame, after resetting the video capture to the same frame number. Is this expected, or am I doing something wrong?

click to hide/show revision 2
No.2 Revision

videocapture reads the same frame differently on multiple calls

Hi, I am new to the forum. I have started using Opencv with Java a few weeks ago. In my program I use videocapture to read frames from an avi file. Yesterday I have noticed that, over different runs of my progrem, the n-th frame read from the file is different from the same n-th frame read from the same file, in a previous run. I have confirmed this by subtracting two copies of the same frame, after resetting the video capture to the same frame number. Is this expected, or am I doing something wrong?

for (int j = 0; j < 100; j++){
    Mat img = new Mat();
    Mat m1 = new Mat();
    Mat m2 = new Mat();

    VideoCapture vc = new VideoCapture(filename);
    vc.set(Videoio.CAP_PROP_POS_FRAMES, 0);
    for (int i = 0; i < 9; i++) vc.grab();
    vc.read(img);
    m1 = img.clone();
    Imgproc.cvtColor(m1, m1, Imgproc.COLOR_BGR2GRAY);
    vc.release();

    vc = new VideoCapture(filename);
    vc.set(Videoio.CAP_PROP_POS_FRAMES, 0);
    for (int i = 0; i < 9; i++) vc.grab();
    vc.read(img);
    m2 = img.clone();
    Imgproc.cvtColor(m2, m2, Imgproc.COLOR_BGR2GRAY);
    vc.release();

    Mat m3 = new Mat();
    Core.absdiff(m1, m2, m3);

    if (Core.countNonZero(m3) > 0)System.out.println(Core.sumElems(m3));
}