Emgu 学习之HelloWorld

安装和配置

系统Win10,VS2013,下载Emgu安装包libemgucv-windesktop-3.4.3.3016

安装到了E:\OpenCV\emgucv-windesktop 3.4.3.3016

打开官方的例子,试着运行HelloWorld,会在E:\OpenCV\emgucv-windesktop 3.4.3.3016\bin下面生成 X64 X86两个文件夹,里面是

新建一个Console工程,添加引用,主要是上面目录下的这四个dll文件

因为我们自己的第一个程序使用到了System.Drawing.Point,所以添加引用

 HelloWorld项目1

using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CVHelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {

            String win1 = "Test Window"; //The name of the window
            CvInvoke.NamedWindow(win1); //Create the window using the specific name

            Mat img = new Mat(200, 400, DepthType.Cv8U, 3); //Create a 3 channel image of 400x200
            img.SetTo(new Bgr(255, 0, 0).MCvScalar); // set it to Blue color

            //Draw "Hello, world." on the image using the specific font
            CvInvoke.PutText(
               img,
               "Hello, world",
               new System.Drawing.Point(10, 80),
               FontFace.HersheyComplex,
               1.0,
               new Bgr(0, 255, 0).MCvScalar);


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

然后根据平台,将X85或者X64文件夹复制到程序目录

效果如下

其他配置

工具,选择项,浏览到Emgu.CV.UI.dll,可以添加控件

还可以将E:\OpenCV\emgucv-windesktop 3.4.3.3016\bin添加到环境变量Path中去。

HelloWorld 项目2

代码

        static void Main(string[] args)
        {
            Mat img=CvInvoke.Imread("faces.png");
            CvInvoke.NamedWindow("读取图像", NamedWindowType.AutoSize);
            CvInvoke.Imshow("读取图像", img);
            CvInvoke.WaitKey(0);  //Wait for the key pressing event
            CvInvoke.DestroyWindow("读取图像"); //Destroy the window if key is pressed
        }

显示图像

猜你喜欢

转载自www.cnblogs.com/noigel/p/10594906.html
今日推荐