Android - OpenCV Imgproc.matchTempate: Method not avaliable [closed]
So I'm following this Guide: http://stackoverflow.com/a/17516753/5...
And everything compiles fine but when I run the App it errors on this line:
Imgproc.matchTemplate(img, templ, result, match_method);
In this Method:
public Mat run(String inFile, String templateFile, String outFile, int match_method)
{
System.out.println("\nRunning Template Matching");
Mat img = Highgui.imread(inFile);
Mat templ = Highgui.imread(templateFile);
// / Create the result matrix
int result_cols = img.cols() - templ.cols() + 1;
int result_rows = img.rows() - templ.rows() + 1;
Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
// / Do the Matching and Normalize
Imgproc.matchTemplate(img, templ, result, match_method);
Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
// / Localizing the best match with minMaxLoc
MinMaxLocResult mmr = Core.minMaxLoc(result);
Point matchLoc;
if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
matchLoc = mmr.minLoc;
} else {
matchLoc = mmr.maxLoc;
}
// / Show me what you got
Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
// Save the visualized detection.
System.out.println("Writing "+ outFile);
Highgui.imwrite(outFile, img);
return img;
}
Debug Error:
LogCat Error:
02-26 08:56:11.613: W/Adreno-EGL(18490): <qeglDrvAPI_eglCreateContext:2450>: EGL_BAD_CONFIG
02-26 08:56:11.613: E/OpenCV_for_Tegra(18490): Cannot create OpenGL context
02-26 08:56:11.618: E/cv::error()(18490): OpenCV Error: Assertion failed (corrsize.height <= img.rows + templ.rows - 1 && corrsize.width <= img.cols + templ.cols - 1) in void cv::crossCorr(const cv::Mat&, const cv::Mat&, cv::Mat&, cv::Size, int, cv::Point, double, int), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/templmatch.cpp, line 70
02-26 08:56:11.619: E/org.opencv.imgproc(18490): imgproc::matchTemplate_10() caught cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/templmatch.cpp:70: error: (-215) corrsize.height <= img.rows + templ.rows - 1 && corrsize.width <= img.cols + templ.cols - 1 in function void cv::crossCorr(const cv::Mat&, const cv::Mat&, cv::Mat&, cv::Size, int, cv::Point, double, int)
My Code:
Main - http://pastebin.com/UwYRN6gN
Matching Template Class - http://pastebin.com/ankDA9MJ
Device: Nexus 5
please paste the relevant parts of your error here ! spare us sifting through your links.
also the error clearly says something else, than your question, read it a bit more carefully.
so, you see, there's just something wrong with your images (or their sizes)
probably the 1st thing to do is, check if they're properly read in.
"not available" only means, that it can't find the src code of it (because it's a native/c++ method)
That was it. I'm glad it turned out to be an error on my end. :)
no fear, you're just a noob.
have fun, flying opencv, and in the future, whenever you read resources(images, cascades, videos,etc), always check the outcome !
hi @Mytheral I am also playing with OpenCV and seems meet to same problem, can you please describe how you solve your error?
@draculaxx There was an issue with my image like berak said I ended up just grabbing the image in android and passing over a bitmap for opencv to Convert with Utils.bitmapToMat(inputBitmap, outputMat)
Hi Mytheral! When you say issue with your image, you mean its size and/or resolution?