Difference between revisions of "CSharp OpenCV"
From Ilianko
Line 7: | Line 7: | ||
*File->New Project->Windows Forms Application->OK | *File->New Project->Windows Forms Application->OK | ||
*File->Save | *File->Save | ||
− | [[EMGU настройки#Референции | + | [[EMGU настройки#Референции]] |
*References->Add Reference->.Net->WindowsBase->OK | *References->Add Reference->.Net->WindowsBase->OK | ||
*References->Add Reference->Browse->C:/EMGU->emgu...->bin->Emgu.CV.dll,Emgu.CV.UI.dll, Emgu.Utils.dll | *References->Add Reference->Browse->C:/EMGU->emgu...->bin->Emgu.CV.dll,Emgu.CV.UI.dll, Emgu.Utils.dll |
Revision as of 07:48, 12 February 2014
1. Конфигуриране на OpenCV със C#.
- Инсталиране на EMGU wrapper
- Инсталиране (Repair) на Microsoft Visual C++ 2010 Redistributable Package (x86)
2. Създаване на проект в C# и добавяне на необходимите библиотеки
- Start->All Programs->MS VS2010 Express -> MS VS2010 Express
- File->New Project->Windows Forms Application->OK
- File->Save
- References->Add Reference->.Net->WindowsBase->OK
- References->Add Reference->Browse->C:/EMGU->emgu...->bin->Emgu.CV.dll,Emgu.CV.UI.dll, Emgu.Utils.dll
- C:/EMGU->emgu...->bin->x86->Object of type - exe, dll, ocx) -> преместват се се всички в директорията debug на приложението
- Desktop->nvcuda.dll премества се в директорията debug на приложението.
3. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Windows.Threading;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private Capture cap = new Capture(0); public Rectangle[] ccc; private CascadeClassifier xxx = new CascadeClassifier(@"haarcascade_frontalface_default.xml"); private Size min = new Size(20,20); private Size max = new Size(300,300); private DispatcherTimer timer = new DispatcherTimer();
private void Form1_Load(object sender, EventArgs e) {
Image<Bgr, Byte> currentFrame = cap.QueryFrame(); this.Size = currentFrame.Size;
timer.Tick += new EventHandler(timer_Tick); timer.Interval = new TimeSpan(0, 0, 0, 0, 35); timer.Start(); }
int i = 0; void timer_Tick(object sender, EventArgs e) { Image<Bgr, Byte> currentFrame = cap.QueryFrame(); Image<Gray, Byte> grayFrame = currentFrame.Convert<Gray, Byte>();
if (i > 35 || i == 0) { ccc = xxx.DetectMultiScale(grayFrame, 1.2, 2, min, max); i = 0;
} i++; foreach (var face in ccc) currentFrame.Draw(face, new Bgr(0, double.MaxValue, 0), 3);
pictureBox1.Image = currentFrame.Bitmap;
} }
}
4.