1 | initial version |
read() = grab() + retrieve()
(check the doc) and I don't know what you get when 1 read() is following N grab() ...
Sorry but what happens using simple read()
like below:
boolean ok1,ok2;
VideoCapture vc1 = new VideoCapture(filename);
// Thread.sleep(500L); // file is loading, wait a bit
ok1 = vc1.read(m1);
vc1.release();
Thread.sleep(1000L); // wait 1 one second to be sure the file has been released
VideoCapture vc2 = new VideoCapture(filename);
// Thread.sleep(500L); // file is loading, wait a bit
ok2 = vc2.read(m2);
vc2.release();
if(ok1 && ok2) {
Mat m3 = new Mat();
Core.absdiff(m1, m2, m3);
int differences = Core.countNonZero(m3);
System.out.println("Total differences: "+differences);
}
else System.out.println("Unable to load both frames");
ok1
(and/or ok2
) can be false
if 1st frame isn't ready as soon as the file has been opened. In this case try some sleep just before read()
2 | No.2 Revision |
read() = grab() + retrieve()
(check the doc) and I don't know what you get when 1 read() is following N grab() ...
Sorry but what happens using simple read()
like below:
boolean ok1,ok2;
VideoCapture vc1 = new VideoCapture(filename);
// Thread.sleep(500L); // file is loading, wait a bit
ok1 = vc1.read(m1);
vc1.release();
Thread.sleep(1000L); // wait 1 one second to be sure the file has been released
VideoCapture vc2 = new VideoCapture(filename);
// Thread.sleep(500L); // file is loading, wait a bit
ok2 = vc2.read(m2);
vc2.release();
if(ok1 && ok2) {
Mat m3 = new Mat();
Core.absdiff(m1, m2, m3);
int differences = Core.countNonZero(m3);
System.out.println("Total differences: "+differences);
}
else System.out.println("Unable to load both frames");
ok1
(and/or ok2
) can be false
if 1st frame isn't ready as soon as the file has been opened. In this case try some sleep just before read()
EDIT: I think you are doing some mistake with loops and functions ... I don't have a java env ready but the C++ code below matches N frames with 0 difference on C++/x64/VS2013/Win7/OpenCV 3.1dev
Mat m1, m2, m3,m4;
bool ok1, ok2;
string filename = "C:/Users/xyz/Desktop/AVSS_AB_Easy_Divx.avi";
VideoCapture vc1(filename);
VideoCapture vc2(filename);
int N = 100;
for (int i = 0; i < N; i++) {
ok1 = vc1.read(m1);
ok2 = vc2.read(m2);
if (ok1 && ok2) {
absdiff(m1, m2, m3);
cvtColor(m3, m4, CV_BGR2GRAY);
int differences = countNonZero(m4);
cout << "Total differences: " << differences << endl;
}
else cout << "Unable to load both frames" << endl;
}