Opencv for Android template matching

Source: Internet
Author: User

Because of this need, so, the template search for the relevant information, but the algorithm is very difficult to see things, especially opencv involved in a lot of mathematical methods.

So just to achieve this function, because the demand is relatively simple, in the Internet also search for the relevant code, directly to use, here is equivalent to reprint:

Code, the pro-test can be used, the effect is good, indeed the mouth to find out.

Original: http://www.itstrike.cn/Question/645ffff0-2862-46b6-a421-b76a37dfc660.html

Class Matchingdemo {public void Run (string inFile, String templatefile, string outFile, int match_method) {Sys        Tem.out.println ("\nrunning Template Matching");        Mat img = highgui.imread (inFile);        Mat Templ = Highgui.imread (templatefile);        /Create the result matrix 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_32FC1);        /Do the Matching and Normalize imgproc.matchtemplate (IMG, Templ, result, Match_method);        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 (Match_method = = Imgproc.tm_sqdiff | | match_method = = imgproc.tm_sqdiff_normed) {matchloc = Mmr.minloc;        } else {matchloc = Mmr.maxloc; }///Show me WHat Got Core.rectangle (IMG, Matchloc, new Point (matchloc.x + templ.cols (), Matchloc.y + templ.ro        WS ()), new Scalar (0, 255, 0));        Save the visualized detection.        System.out.println ("Writing" + outFile);    Highgui.imwrite (OutFile, IMG);         }}public class Templatematching {public static void main (string[] args) {system.loadlibrary ("opencv_java246");    New Matchingdemo (). Run (Args[0], args[1], args[2], Imgproc.tm_ccoeff); }}

Target Image:

Template Image:

Post-Search Image:

Opencv for Android template matching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.