OpenCV 的 .Net 介面

來源:互聯網
上載者:User

Emgu CV 是 OpenCV 跨平台的 C# 封裝包,主要是為了方便在 C# 裡使用 OpenCV 的庫函數,下載和安裝都很簡單,建立一個 C# 控制視窗程序後,Hello World 例子代碼如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using Emgu.CV;using Emgu.Util;using Emgu.CV.Structure;namespace OpenCVTester{    class Program    {        static void Main(string[] args)        {            //The name of the window            String win1 = "Test Window";            //Create the window using the specific name            CvInvoke.cvNamedWindow(win1);            //Create an image of 400x200 of Blue color            using (Image<Bgr, Byte> img = new Image<Bgr, byte>(400, 200, new Bgr(255, 0, 0)))            {                //Create the font                MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0);                //Draw "Hello, world." on the image using the specific font                img.Draw("Hello, world", ref f, new Point(10, 80), new Bgr(0, 255, 0));                //Show the image                CvInvoke.cvShowImage(win1, img.Ptr);                //Wait for the key pressing event                CvInvoke.cvWaitKey(0);                //Destory the window                CvInvoke.cvDestroyWindow(win1);            }        }    }}

這裡需要注意的是,如果用 Visual Studio 2008 來調試上面的代碼,則記得要把 OpenCV 相關的動態連結程式庫放到你測試工程的這個目錄裡:

\bin\Debug

否則在跑到下面這句代碼

CvInvoke.cvNamedWindow(win1);

的時候,就會彈出一個莫名其妙的出錯框,提示如下錯誤:

未處理的"System.TypeInitializationException"類型的異常出現在 OpenCVTester.exe 中。其他資訊: "Emgu.CV.CvInvoke"的類型初始值設定項引發異常

看來,C#調試時的程式動態連結程式庫讀取位置,還比較特殊呀~~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.