Ask Your Question

Revision history [back]

OpenCV with Android Template Matching using camera images.

Hi, I have to developed template matching for android device. That application will capture the image using camera and matched with my existing template.

I am facing problem in when i captured the image that image will be darkens , lighter or blued, In this case my algorithm was failed.

My question is that Did I need to process photo? while Template matching.

public boolean run(Mat originalMat, Mat templ, Mat outPutMat, int match_method) {
    Mat Img = originalMat;
    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);
    Imgproc.threshold(result, result, 0.8, 1., Imgproc.THRESH_TOZERO);
    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;
    }
    if (mmr.maxVal > .70) {

    } else {
        return false;
    }
    return false;
}

Thanks...