วันเสาร์ที่ 13 กรกฎาคม พ.ศ. 2556

การเขียนโปรแกรม Image Processing ด้วย x64 VC#2010 และ OpenCV


โปรแกรมที่ต้องมี
1.       Visual C# 2010  x64
2.       EMGU CV for x64 version 2.4.9.1847 หรือ version ใหม่กว่า ใครยังไม่มีคลิกที่นี่ download
3.       DotNet 3.0 ขึ้นไป
4.       สำหรับการแก้ปัญหา Dependency ให้ใช้ MSVCRT 9.0 SP1 x64 ในการแก้ปัญหานี้
เริ่มต้นใช้งาน
1.       Install VC# 2010
2.       Install EMGU CV
3.       ตั้งค่า System path:
- ไปที่
Computer คลิกขวา >> Properties >> Advance System Settings >> Environment Variables
- ที่กรอบ
System variable เลื่อนไปหาบรรทัด PATH >> Edit เลื่อน cursor ไปท้ายสุดและเพิ่ม folder bin จากPath ที่ลง EMGUไว้ (โดยปกติถ้าไม่เปลี่ยนขณะที่ Install จะเป็น C:/EMGU/bin หรือ C:\Emgu\emgucv-windows-universal-gpu 2.4.9.1847\bin)
  



4.       สร้าง Project VC# ขึ้นมา
5.       เพิ่ม Reference ให้กับ Project
คลิกขวาที่ Reference Add Reference

เลือก Tab Browse หา folder bin ที่ลง EMGU ไว้ (เช่น C:\EMGU\bin\x64 หรือ C:\Emgu\emgucv-windows-universal-gpu 2.4.9.1847\bin\x64)  à เลือก
-          Emgu.CV.dll
-          Emgu.CV.GPU.dll
-          Emgu.CV.ML.dll
-          Emgu.CV.UI.dll
-          Emgu.Util.dll
-          อื่น ๆ ตามแต่ต้องการใช้งาน
-          คลิก OK

6.       เรียกใช้งาน dll ที่ add เข้าไป โดยคำสั่ง using ที่ header ของ project  
-         using Emgu.CV;
-         using Emgu.CV.CvEnum;
-         using Emgu.CV.Structure;
1.  using System;  
2.  using System.Collections.Generic;  
3.  using System.ComponentModel;  
4.  using System.Data;  
5.  using System.Drawing;  
6.  using System.Linq;  
7.  using System.Text;  
8.  using System.Windows.Forms;  
9.    
10. using Emgu.CV;  
11. using Emgu.CV.CvEnum;  
12. using Emgu.CV.Structure;  
13.   

7.       Copy ไลบรารี่ ไฟล์เหล่านี้จาก folder (C:\EMGU\bin\x64 หรือ C:\Emgu\emgucv-windows-universal-gpu 2.4.9.1847\bin\x64) ไปยัง execute folder ของ Visual C# Project ของเรา
-          opencv_calib3d249.dll,
-          opencv_contrib249.dll, 
-          opencv_core249.dll, 
-          opencv_features2d249.dll, 
-          opencv_ffmpeg249.dll,
-          opencv_flann249.dll, 
-          opencv_gpu249.dll, 
-          opencv_highgui249.dll, 
-          opencv_imgproc249.dll, 
-          opencv_legacy249.dll, 
-          opencv_ml249.dll,
-          opencv_objdetect249.dll, 
-          opencv_video249.dll และ
-         cvextern.dll 
8.       Copy GPU Package จาก folder (C:\EMGU\bin\x64 หรือ C:\Emgu\emgucv-windows-universal-gpu 2.4.9.1847\bin\x64) ไปที่ execute folder ของ Visual C# Project ของเรา
-          cudart64_50_35.dll และ 
-          npp64_50_35.dll
9.       เพิ่มค่ำสั่งเพื่อทดสอบการตั้งค่า โดยสั่งให้เปิดภาพขึ้นมาบน picturebox
14.   private void button1_Click(object sender, EventArgs e)  
15.   {  
16.       Image<Bgr, Byte> img = new Image<Bgr, Byte>("ภาพที่ต้องการเปิด");  
17.       pictureBox1.Image = img.ToBitmap(pictureBox1.Width, pictureBox1.Height);
18.     }  

รายละเอียดเพิ่มเติม http://www.emgu.com/wiki/index.php/Download_And_Installation

ไม่มีความคิดเห็น:

แสดงความคิดเห็น