OpenCV的使用Android中的模板匹配 [英] Template Matching in Android using openCV

查看:1644
本文介绍了OpenCV的使用Android中的模板匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想配合使用模板匹配Android中的摄像机输入的图像。当我尝试这与静态图像2中一样在这里:<一href=\"http://stackoverflow.com/questions/17001083/opencv-template-matching-example-in-android/17516753?noredirect=1#comment28832789_17516753\">OpenCV模板匹配在Android中的例子,一切都运行得很好。但是,当我尝试从相机用拍摄的图像,我没有得到正确的结果。以下是我写的code:

I'm trying to match an image with the camera input in Android using template matching. When i try this with static 2 images like in here: OpenCV Template Matching example in Android, everything works just fine. But when I try to use the captured images from the camera, I do not get the correct result. Following is the code that I have written:

  String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();


                Mat img = Highgui.imread(baseDir + "/mediaAppPhotos/img2.png");
                Mat templ = Highgui.imread(baseDir+ "/mediaAppPhotos/chars.png");


                int result_cols = img.cols() - templ.cols() + 1;
                int result_rows = img.rows() - templ.rows() + 1;
                Mat result = new Mat(result_cols, result_rows, CvType.CV_32FC1);

                // / Do the Matching and Normalize
                Imgproc.matchTemplate(img, templ, result, Imgproc.TM_CCOEFF);
                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 (Imgproc.TM_CCOEFF == Imgproc.TM_SQDIFF
                        || Imgproc.TM_CCOEFF == Imgproc.TM_SQDIFF_NORMED) {
                    matchLoc = mmr.minLoc;
                } else {
                    matchLoc = mmr.maxLoc;
                }

                // / Show me what you got
                Core.rectangle(
                        img,
                        matchLoc,
                        new Point(matchLoc.x + templ.cols(), matchLoc.y
                                + templ.rows()), new Scalar(0, 255, 0));

                // Save the visualized detection.
                System.out.println("Writing " + baseDir+ "/mediaAppPhotos/result.png");
                Highgui.imwrite(baseDir + "/mediaAppPhotos/result.png", img);

欲这种模板匹配时,图像从摄像机捕获以及工作。任何帮助是极大AP preciated!

I want to this template matching to work when the image is captured from the camera as well. Any help is greatly appreciated!

推荐答案

也许是这样的:

https://play.google.com/store/apps/details?id=in.mustafaak.imagematcher&hl=es_419

在github上提供code

code available in github

这篇关于OpenCV的使用Android中的模板匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆