【发布时间】:2015-07-22 18:03:11
【问题描述】:
我在这里看到了一些与我的错误有关的问题,例如this 和this,我知道如果图像和模板不同,我无法执行Imgproc.matchTemplate() 方法数据类型。但是我仍然对如何知道我使用的是什么类型的Mat 感到困惑。
以下是我改编自示例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
}
所以基本上我要做的是从inputFrame 的子垫中获取mImage,然后将模板过程与其他 24 张图片进行匹配,并确定哪一张具有最佳价值(最低或最高)。然而错误表明了这一点。
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
我尝试先用相同的类型初始化mImage 和mTemplate,但仍然没有运气。有什么建议吗?之前谢谢。
【问题讨论】:
-
因为这个问题stackoverflow.com/q/29238433/1180117中的断言是相同的 - 这个答案可能会有所帮助。
标签: android opencv image-processing