Ask Your Question

Pacobo's profile - activity

2013-09-23 02:20:46 -0600 commented question Android camera streaming and matchTemplates, suggestion?

Done, but the problem is the size of the picture, now I take a submatrix and it's better :D

2013-09-19 08:25:20 -0600 received badge  Editor (source)
2013-09-19 04:42:37 -0600 commented question Android camera streaming and matchTemplates, suggestion?

I don't want a QR-decode/encoder, I want to recognize a simple pattern really similar to the QR-code. Sorry if I hadn't explained it correctly.

Also, sorry for not write all the things you said StevenPuttermans, I tried to keep it simple, an example of camera streaming and matchTemplate. I'm trying to organize everything and upload it.

2013-09-19 03:59:09 -0600 asked a question Android camera streaming and matchTemplates, suggestion?

<edit!!>

I want to recognize a specific pattern ( This is the pattern ) with Android camera. I 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 anywhere... </edit!!>

Thank you!