Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

minVal & maxVal = 0.0 with TemplateMatching Android

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

}