I've seen some questions here that is related to my error such as this and this and I know that I can't execute Imgproc.matchTemplate()
method if the image and the template don't have the same datatype. But I'm still confused on how to know what type of Mat
I'm using.
Below is my code which I adapted from example here:
for (int i = 0; i < 24; i++) {
arrDraw[i] = getResources().getIdentifier("let" + i, "drawable", getPackageName());
}
Mat mImage = input.submat(bigRect);
for (int i = 0; i < 24; i++) {
Mat mTemplate = Utils.loadResource(this, arrDraw[i], Highgui.CV_LOAD_IMAGE_COLOR);
Mat mResult = new Mat(mImage.rows(), mImage.cols(), CvType.CV_32FC1);
Imgproc.matchTemplate(mImage, mTemplate, mResult, match_method);
Core.normalize(mResult, mResult, 0, 1, Core.NORM_MINMAX, -1, new Mat());
... // further process
}
So basically what I'm trying to do is take a mImage
from submat of inputFrame
and do match template process with 24 other pictures and decide which has the best value (either lowest or highest). Yet the error shows this.
OpenCV Error: Assertion failed ((img.depth() == CV_8U || img.depth() == CV_32F) && img.type() == templ.type()) in void cv::matchTemplate(cv::InputArray, cv::InputArray, cv::OutputArray, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/templmatch.cpp, line 249
I tried to initialize the mImage
and mTemplate
first with the same type but still no luck. Any advice? Thanks before.