MatchTemplate exception in android-opencv

asked 2013-07-30 08:37:21 -0500

sp_mic88 gravatar image

I am developing an Android application, using Opencv libraries (version 2.4.5). The application simply opens a video stream and captures frames from it. Every frame is processed with image-processing techniques in order to detect faces and, within them, features (fiducial points).

I use, for eyes, the matchTemplate method, and sometimes, I have this error:

 07-30 11:26:44.355: ERROR/AndroidRuntime(23441): FATAL EXCEPTION: Thread-10570
    CvException [org.opencv.core.CvException: /home/reports/ci/slave_desktop/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)
    ]
    at org.opencv.imgproc.Imgproc.matchTemplate_0(Native Method)
    at org.opencv.imgproc.Imgproc.matchTemplate(Imgproc.java:7226)
    at com.micaela.myapp.Eye.match(Eye.java:265)
    at com.micaela.myapp.Eye.access$100(Eye.java:22)
    at com.micaela.myapp.Eye$4.run(Eye.java:172)
    at java.lang.Thread.run(Thread.java:856)

I don't understand what is corrsize. The piece of code that throws this exception is:

  Mat res;
  if ((roi.height() > MainActivity.tpl.height()) && (roi.width() > MainActivity.tpl.width())) {
        res = new Mat(new Size(roi.cols() - MainActivity.tpl.cols() + 1, roi.rows() - MainActivity.tpl.rows() + 1), CvType.CV_32FC1);
       if((roi.depth() == CvType.CV_8U || roi.depth() == CvType.CV_32F) && roi.type() == MainActivity.tpl.type()) { //altra eccezione che veniva lanciata!
                Imgproc.matchTemplate(roi, MainActivity.tpl, res, Imgproc.TM_SQDIFF);
                if (left) {
                    return new Point((eyeRect.x + this.roi.width() - matchRect.x - Math.round(Core.minMaxLoc(res).maxLoc.x + (MainActivity.tpl.width() / 2))),
                            (Math.round(Core.minMaxLoc(res).maxLoc.y + (MainActivity.tpl.height() / 2)) + matchRect.y + eyeRect.y));
                } else {
                    return new Point((Math.round(Core.minMaxLoc(res).maxLoc.x + (MainActivity.tpl.width() / 2)) + matchRect.x + eyeRect.x), (Math.round(Core.minMaxLoc(res).maxLoc.y + (MainActivity.tpl.height() / 2)) + matchRect.y + eyeRect.y));
                }
            }
        }
edit retag flag offensive close merge delete