找出姚明: EmguCV视觉计算,模板匹配法源码


EmguCV视觉计算,模板匹配的C#源码例程。平台为最新 VS2017+EmguCV 3.3。模板匹配,就是在一幅图像中寻找另一幅模板图像最匹配(也就是最相似)的部分的技术。
资源截图
代码片段和文件信息

using System.Drawing;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;

namespace MatchSample
{
    class Program
    {
        static void Main(string[] args)
        {
            Mat img templ result;

            img = CvInvoke.Imread(“nba.jpg“); //ImreadModes.AnyColor //nba.jpg
            templ = CvInvoke.Imread(“yaoming.png“); //nwcj.png --模板图片

            int result_cols = img.Cols - templ.Cols + 1;
            int result_rows = img.Rows - templ.Rows + 1;

            result = new Mat();
            result.Create(result_cols result_rows DepthType.Cv32F1);

            //标准方差匹配: TemplateMatchingType.SqdiffNormed
            CvInvoke.MatchTemplate(img templ result TemplateMatchingType.SqdiffNormed);//这里我们使用的匹配算法是标准平方差匹配 method=CV_TM_SQDIFF_NORMED,数值越小匹配度越好/TemplateMatchingType.CcoeffNormed
            CvInvoke.Normalize(result result 0 1 NormType.MinMaxDepthType.Cv32F new Mat()); // new Mat()
            //normalize(result result 0 1 NORM_MINMAX -1 Mat());

            double minVal = -1;
            double maxVal = -1;
            Point minLoc = new Point(00);
            Point maxLoc = new Point(0 0);
            Point matchLoc = new Point(0 0);

            CvInvoke.MinMaxLoc(result ref minVal ref maxVal ref minLoc ref maxLoc new Mat()); // new Mat()
            matchLoc = minLoc;

            //CvInvoke.Rectangle(img matchLocnew Point(matchLoc.X + templ.Cols matchLoc.Y + templ.Rows) new MCvScalar(0 255 0) 2 8 0);
            CvInvoke.Rectangle(img new Rectangle(matchLoc.X  matchLoc.Y  templ.Cols templ.Rows) new MCvScalar(0 255 0) 1 LineType.AntiAlias 0);

            //Rectangle(int x int y int width int height);

            CvInvoke.Imshow(“img“ img); //Show the image
            CvInvoke.WaitKey(0);  //Wait for the key pressing event
            CvInvoke.DestroyWindow(“img“); //Destroy the window if key is pressed

        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-15 11:12  MatchSample
     文件        2415  2018-03-15 10:48  MatchSampleMatchSample.csproj
     文件        2077  2018-03-15 11:12  MatchSampleProgram.cs
     目录           0  2018-03-15 10:08  MatchSampleProperties
     文件        1338  2018-03-15 10:08  MatchSamplePropertiesAssemblyInfo.cs
     目录           0  2018-03-15 10:08  MatchSamplein
     目录           0  2018-03-15 11:11  MatchSampleinDebug
     文件        7680  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.DebuggerVisualizers.VS2012.dll
     文件        7680  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.DebuggerVisualizers.VS2013.dll
     文件        7680  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.DebuggerVisualizers.VS2015.dll
     文件        7680  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.DebuggerVisualizers.VS2017.dll
     文件       27136  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.UI.GL.dll
     文件        2242  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.UI.GL.xml
     文件      117760  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.UI.dll
     文件       34738  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.UI.xml
     文件      622592  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.World.dll
     文件     1706860  2017-10-31 01:08  MatchSampleinDebugEmgu.CV.World.xml
     文件        5632  2018-03-15 11:12  MatchSampleinDebugMatchSample.exe
     文件       11776  2018-03-15 11:12  MatchSampleinDebugMatchSample.pdb
     文件      307200  2017-09-03 03:57  MatchSampleinDebugedGraph.dll
     文件     1492968  2017-09-03 03:57  MatchSampleinDebugedGraph.xml
     目录           0  2018-03-15 10:49  MatchSampleinDebuglibs
     目录           0  2018-03-15 10:49  MatchSampleinDebuglibsx64
     文件      331432  2017-08-21 22:56  MatchSampleinDebuglibsx64concrt140.dll
     文件    32104448  2017-10-31 01:08  MatchSampleinDebuglibsx64cvextern.dll
     文件     2320978  2017-10-31 01:08  MatchSampleinDebuglibsx64cvextern.lib
     文件      641696  2017-08-21 22:56  MatchSampleinDebuglibsx64msvcp140.dll
     文件    17806336  2017-10-31 00:40  MatchSampleinDebuglibsx64opencv_ffmpeg330_64.dll
     文件       87728  2017-08-21 22:56  MatchSampleinDebuglibsx64vcruntime140.dll
     目录           0  2018-03-15 10:49  MatchSampleinDebuglibsx86
     文件      242496  2017-08-21 22:56  MatchSampleinDebuglibsx86concrt140.dll
............此处省略34个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)