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!
1 | initial version |
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!
2 | retagged |
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!
3 | No.3 Revision |
<edit!!>
I want to recognite recognize a specific pattern as QR-code has. ( ) 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!