Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Android - OpenCV Imgproc.matchTempate: Method not avaliable

So I'm following this Guide: http://stackoverflow.com/a/17516753/584994

And everything compiles fine but when I run the App it errors on this line:

Imgproc.matchTemplate(img, templ, result, match_method);

and throws this error:

enter image description here

That says that Imgproc.matchtemplate is not available but the guide is written for android so I'm a bit confused. Did something change in OpenCV 2.4.10?

My Code:
Main - http://pastebin.com/UwYRN6gN
Matching Template Class - http://pastebin.com/ankDA9MJ

LogCat Error: http://pastebin.com/MmbnntSD

Device: Nexus 5

Android - OpenCV Imgproc.matchTempate: Method not avaliable

So I'm following this Guide: http://stackoverflow.com/a/17516753/584994

And everything compiles fine but when I run the App it errors on this line:

Imgproc.matchTemplate(img, templ, result, match_method);

and throws this error:

enter image description here

That says that Imgproc.matchtemplate is not available but the guide is written for android so java and I'm a bit confused. Did something change in OpenCV 2.4.10?using OpenCV4Android.

My Code:
Main - http://pastebin.com/UwYRN6gN
Matching Template Class - http://pastebin.com/ankDA9MJ

LogCat Error: http://pastebin.com/MmbnntSD

Device: Nexus 5

Android - OpenCV Imgproc.matchTempate: Method not avaliable

So I'm following this Guide: http://stackoverflow.com/a/17516753/584994

And everything compiles fine but when I run the App it errors on this line:

Imgproc.matchTemplate(img, templ, result, match_method);

and throws this error:Debug Error:

enter image description here

That says that Imgproc.matchtemplate is not available but the guide is written for java and I'm using OpenCV4Android.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

LogCat Error: http://pastebin.com/MmbnntSD

Device: Nexus 5

Android - OpenCV Imgproc.matchTempate: Method not avaliable

So I'm following this Guide: http://stackoverflow.com/a/17516753/584994

And everything compiles fine but when I run the App it errors on this line:

Imgproc.matchTemplate(img, templ, result, match_method);

Debug Error:

enter image description here

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

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;
    }

Device: Nexus 5

Android - OpenCV Imgproc.matchTempate: Method not avaliable

So I'm following this Guide: http://stackoverflow.com/a/17516753/584994

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:

enter image description here

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

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;
    }

Device: Nexus 5