minVal & maxVal = 0.0 with TemplateMatching Android

asked 2013-04-22 04:03:26 -0500

Marwen Z gravatar image

Hi i use this code link text but it gives me minVal=maxVal=0.0 !

public void TemplateMatching(Mat mFind,Bitmap dst)
    {

        Mat  Input = new Mat(mFind.width(), mFind.height(), CvType.CV_8UC4);
        Utils.bitmapToMat(dst, Input);
        Mat  mResult8u = new Mat(mFind.width(), mFind.height(), CvType.CV_8UC4);
        Mat mResult9u = new Mat(mFind.width(), mFind.height(), CvType.CV_8UC4);
        Mat mResult = new Mat(mFind.width(), mFind.height(), CvType.CV_8UC4);

        Imgproc.matchTemplate(mFind, Input, mResult, Imgproc.TM_CCOEFF_NORMED);
        Core.normalize(mResult, mResult9u, 0, 255, Core.NORM_MINMAX, CvType.CV_8U); 
        MinMaxLocResult locRes = Core.minMaxLoc(mResult9u);  
        double minVal = locRes.minVal;  
        Point minLoc = locRes.minLoc;
        double maxVal = locRes.maxVal;  
        Point maxLoc = locRes.maxLoc;
        maxLoc.x+=25;
        maxLoc.y+=25;

        Point point = new Point();
        point.x=maxLoc.x+Input.cols();
        point.y=maxLoc.y+Input.rows();

             double thresholds=0.08;
Log.w("max val", maxVal+"");
Log.w("min val", minVal+"");
if(maxVal>=thresholds)
        Core.rectangle(mFind, maxLoc,point, new Scalar(0, 255, 0, 255), 3);

        Bitmap bmp3= Bitmap.createBitmap(mFind.cols(), mFind.rows(),Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(mFind, bmp3);     

        imgb.setImageBitmap(bmp3);

}
edit retag flag offensive close merge delete