Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is it possible the pattern recognition in android?

I want to recognite a pattern as QR-code has. I thought it could be easy with OpenCV and MatchTemplate but I cann't use it. I don't know why. Has somebody an example with camera streaming?

Thank you!

click to hide/show revision 2
retagged

updated 2013-09-19 04:00:51 -0600

berak gravatar image

Is it possible the pattern recognition in android?

I want to recognite a pattern as QR-code has. I thought it could be easy with OpenCV and MatchTemplate but I cann't use it. I don't know why. Has somebody an example with camera streaming?

Thank you!

Is it possible the pattern recognition in android?Android camera streaming and matchTemplates, suggestion?

<edit!!>

I want to recognite recognize a specific pattern as QR-code has. ( This is the pattern ) with Android camera. I thought took the OpenCV Tutorial1 and developed this:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    mRgba = inputFrame.rgba();

    AssetManager a = getAssets();
    InputStream i = null;
    try {
        i = a.open("pattern.png");
    } catch (IOException e) {
        e.printStackTrace();
    }
    Drawable d = Drawable.createFromStream(i, "pattern");
    Bitmap bb = ((BitmapDrawable) d).getBitmap();
    Mat templ = new Mat();
    Utils.bitmapToMat(bb, templ);

    int match_method = Imgproc.TM_CCOEFF;

    Mat img = inputFrame.rgba();
    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_8U);
    Log.i("WWW", "mat: " + img.channels() + " " + templ.channels() + " "
            + result.channels());
    Imgproc.matchTemplate(img, templ, result, match_method);
    Log.i("WWW", "matchTemplate");
    Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
    Log.i("WWW", "normalize");
    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;
    }
    Core.rectangle(mRgba, matchLoc, new Point(matchLoc.x + templ.cols(),
            matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
    Log.i("WWW", "square");

    return mRgba;
}

As you could see, the image is loaded in each frame, that's because I'm so idiot and cann't load it could be easy with OpenCV and MatchTemplate but I cann't use it. I don't know why. Has somebody an example with camera streaming?anywhere... </edit!!>

Thank you!