I took screenshots of each slide of the powerpoint and stored them into an ArrayList
of Mats, I am trying to see when I reach the end of the slide show so I use a compare function. However, the implementation gives an exception on the countNonZero
function:
E/cv::error(): OpenCV(3.4.5) Error: Assertion failed (cn == 1) in int cv::countNonZero(cv::InputArray), file /build/3_4_pack-android/opencv/modules/core/src/count_non_zero.cpp, line 298 E/org.opencv.core: core::countNonZero_10() caught cv::Exception: OpenCV(3.4.5) /build/3_4_pack-android/opencv/modules/core/src/count_non_zero.cpp:298: error: (-215:Assertion failed) cn == 1 in function 'int cv::countNonZero(cv::InputArray)' D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.autoslide, PID: 27129 CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.5) /build/3_4_pack-android/opencv/modules/core/src/count_non_zero.cpp:298: error: (-215:Assertion failed) cn == 1 in function 'int cv::countNonZero(cv::InputArray)' ]
Here is the code:
private void getScreens(WebView view) {
int i = 0;
do {
Bitmap b = Screenshot.takeScreenshot(view);
//imageView.setImageBitmap(b);
Mat mat = new Mat();
Utils.bitmapToMat(b.copy(Bitmap.Config.ARGB_8888, true), mat);
screens.add(mat);
view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT));
i++;
//System.out.println(screens.size());
} while(i <= 4 || !(matEquals(screens.get(i-1), screens.get(i-2))));
}
public static boolean matEquals(Mat img1, Mat img2){
Mat out = new Mat();
Core.compare(img1, img2, out, Core.CMP_NE);
return Core.countNonZero(out) == 0;
}