Android camera streaming and matchTemplates, suggestion? [closed]
<edit!!>
I want to recognize a specific 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!
think again. just knowing that it's a qr code, won't help you much.
you'll probably need a decoder library for this, too.
Actually your question exists of 3 parts. First the QR code part, then the part where you don't succeed in using openCV and matchTemplate, then the fact that you need help on camera streaming. I suggest you update your question, make it clear, add some example code you tried which failed, supply your system configuration, ... only then people will feel the urge to actually help you out.
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.
Then again, place your pattern here, add your code and tell us where it goes wrong. Then we will help you out. This is not a ask and get ready made code forum.
Why dont you create a global variable for the input image and load it for example in your OnCreate() function?
Done, but the problem is the size of the picture, now I take a submatrix and it's better :D
If your question was solved, then feel free to post your solution and accept it as an answer so that it shows solved.