Android - OpenCV Imgproc.matchTempate: Method not avaliable [closed]

asked 2015-02-26 07:58:54 -0600

Mytheral gravatar image

updated 2015-02-26 08:38:21 -0600

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:

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

Device: Nexus 5

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2015-02-26 09:20:13.085028

Comments

1

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.

berak gravatar imageberak ( 2015-02-26 08:15:22 -0600 )edit
1

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.

berak gravatar imageberak ( 2015-02-26 08:38:07 -0600 )edit
1

"not available" only means, that it can't find the src code of it (because it's a native/c++ method)

berak gravatar imageberak ( 2015-02-26 08:51:48 -0600 )edit
1

That was it. I'm glad it turned out to be an error on my end. :)

Mytheral gravatar imageMytheral ( 2015-02-26 09:15:22 -0600 )edit
1

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 !

berak gravatar imageberak ( 2015-02-26 09:19:03 -0600 )edit

hi @Mytheral I am also playing with OpenCV and seems meet to same problem, can you please describe how you solve your error?

draculaxx gravatar imagedraculaxx ( 2015-03-18 10:14:35 -0600 )edit

@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)

Mytheral gravatar imageMytheral ( 2015-03-18 12:18:51 -0600 )edit

Hi Mytheral! When you say issue with your image, you mean its size and/or resolution?

Humberto gravatar imageHumberto ( 2016-04-04 08:40:57 -0600 )edit