13/11/2011, 22:35
1. Ta tạo ra 2 control là ImageBox và Timer1, theo hình vẽ.
Code của tôi sẽ tự động resize bức ảnh cho phù hợp với ImageBox nên bạn
có thể vẽ ImageBox thoải mái
[You must be registered and logged in to see this link.]
2. Thiết lập Properties của Timer1 với Interval là 100 và Enable nó lên. Nhấn đôi vào Timer1, chèn đoạn mã sau vào:
[You must be registered and logged in to see this link.]
3. Khai báo các biến
[You must be registered and logged in to see this link.]
4. Trước khi thêm 2 dòng code sau vào Form1_Load, các bạn chép file “haarcascade_frontalface_alt.xml” tại C:\Emgu\emgucv-windows-x86 2.3.0.1416\opencv\data\haarcascades\ (đường dẫn tùy thuộc vào nơi bạn đã cài Emgu)
[You must be registered and logged in to see this link.]
5. Tận hưởng thành quả nào
[You must be registered and logged in to see this link.]
Sourcecode có thể được download tại [You must be registered and logged in to see this link.]
Tra cứu Documentation tại đây : [You must be registered and logged in to see this link.]
Code của tôi sẽ tự động resize bức ảnh cho phù hợp với ImageBox nên bạn
có thể vẽ ImageBox thoải mái
[You must be registered and logged in to see this link.]
2. Thiết lập Properties của Timer1 với Interval là 100 và Enable nó lên. Nhấn đôi vào Timer1, chèn đoạn mã sau vào:
[You must be registered and logged in to see this link.]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | private void timer1_Tick(object sender, EventArgs e) { using (Image { if (nextFrame != null) { // there's only one channel (greyscale), hence the zero index //var faces = nextFrame.DetectHaarCascade(haar)[0]; Image var faces = grayframe.DetectHaarCascade( haar, 1.4, 4, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(nextFrame.Width / 8, nextFrame.Height / 8 ) )[0]; foreach (var face in faces) { nextFrame.Draw(face.rect, new Bgr(0, 255, 0), 3); } Image showimg = nextFrame.Resize(pictureBox1.Width,pictureBox1.Height,0); pictureBox1.Image = showimg.ToBitmap(); } } } |
3. Khai báo các biến
[You must be registered and logged in to see this link.]
1 2 | private Capture cap; private HaarCascade haar; |
4. Trước khi thêm 2 dòng code sau vào Form1_Load, các bạn chép file “haarcascade_frontalface_alt.xml” tại C:\Emgu\emgucv-windows-x86 2.3.0.1416\opencv\data\haarcascades\ (đường dẫn tùy thuộc vào nơi bạn đã cài Emgu)
[You must be registered and logged in to see this link.]
1 2 3 4 5 6 7 | private void Form1_Load(object sender, EventArgs e) { // passing 0 gets zeroth webcam cap = new Capture(0);//sử dụng webcam có index là 0 // adjust path to find your xml haar = new HaarCascade("..\..\haarcascade_frontalface_alt.xml"); } |
5. Tận hưởng thành quả nào
[You must be registered and logged in to see this link.]
Sourcecode có thể được download tại [You must be registered and logged in to see this link.]
Tra cứu Documentation tại đây : [You must be registered and logged in to see this link.]