Simple VB.Net Video/Webcam Capture

Ask questions on using Emgu CV with VB

Simple VB.Net Video/Webcam Capture

Postby bangonkali » Mon Jul 19, 2010 1:27 am

I think there are not much samples given for VB.NET programmers here in EmguCV. So i just think it may help a lot of people if examples are added in the Wiki. I hope this one helps too.

Code: Select all
Imports Emgu.CV
Imports Emgu.CV.Structure
Imports Emgu.CV.Util
Imports Emgu.CV.UI

Public Class frmMain
    Dim imgFrame As Image(Of Bgr, Byte)
    Dim vidCapture As Capture

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        vidCapture = New Capture() ' Put the proper arguments in here
        AddHandler Application.Idle, AddressOf AppIdle
    End Sub

    Public Sub AppIdle(ByVal sender As System.Object, ByVal e As System.EventArgs)
        imgFrame = vidCapture.QueryFrame
        imgBox.Image = imgFrame ' this is where captured image go.
    End Sub
End Class
bangonkali
 
Posts: 4
Joined: Mon Jul 19, 2010 1:10 am

Re: Simple VB.Net Video/Webcam Capture

Postby MIG400 » Sun Aug 01, 2010 8:46 am

Hi, thanks for help, I'm using your code and work, I haven't a webcam right now but I capture images from a .avi,

vidCapture = New Capture("video.avi")

I'm having a problem cause the file .avi is in colors but when I captures the video is in gray, I'm using

Dim imgFrame As Image(Of Bgr, Byte)

Like de example. What I'm doing bad? :cry:

Thanks again.
MIG400
 
Posts: 18
Joined: Sun Aug 01, 2010 8:37 am

Re: Simple VB.Net Video/Webcam Capture

Postby cke » Sat Aug 07, 2010 5:30 am

hi, what if i want to do a face detection on the webcam capture?
cke
 
Posts: 2
Joined: Sat Aug 07, 2010 5:20 am

Re: Simple VB.Net Video/Webcam Capture

Postby bangonkali » Sat Aug 07, 2010 6:04 am

MIG400 wrote:Hi, thanks for help, I'm using your code and work, I haven't a webcam right now but I capture images from a .avi,

vidCapture = New Capture("video.avi")

I'm having a problem cause the file .avi is in colors but when I captures the video is in gray, I'm using

Dim imgFrame As Image(Of Bgr, Byte)

Like de example. What I'm doing bad? :cry:

Thanks again.


Sorry for the late reply. But i'm quite sure that if your video is colored the code should also output colored frames since we're not limiting it to "Image(Of Gray, Byte)", perhaps the problem lies on the decoding of the video. Try to test on different codecs to see the effects. Perhaps the problem's on the codec.
bangonkali
 
Posts: 4
Joined: Mon Jul 19, 2010 1:10 am

Re: Simple VB.Net Video/Webcam Capture

Postby bangonkali » Sat Aug 07, 2010 6:11 am

cke wrote:hi, what if i want to do a face detection on the webcam capture?


It should look something like this:
Code: Select all
imgFrame = New Image(Of Bgr, Byte)(file)
For Each face As MCvAvgComp In imgFrame.DetectHaarCascade(objectToDetect)(0)
        imgFrame.Draw(face.rect, New Bgr(Color.Red), 2)
Next

Where file is a string path to the image file, and objectToDetect is declared as:
Code: Select all
Dim objectToDetect As New HaarCascade(Application.StartupPath & "\haarcascade_frontalface_alt2.xml")

... where "Application.StartupPath & "\haarcascade_frontalface_alt2.xml" points to the appropriate haar file. In this example, rectangles are drawn on each face after they're found.
bangonkali
 
Posts: 4
Joined: Mon Jul 19, 2010 1:10 am

Re: Simple VB.Net Video/Webcam Capture

Postby cke » Sun Aug 08, 2010 3:25 am

thanks bangonkali, i've done that already.. but my problem now is, when i try to put imgFrame as the frame capture inside an image viewer control, the displayed capture slows down because of the detection process. i can't figure out what to do. can you help me? i'm also planning to put an automatic face recognition in my project. thanks again!
cke
 
Posts: 2
Joined: Sat Aug 07, 2010 5:20 am

Re: Simple VB.Net Video/Webcam Capture

Postby MIG400 » Sun Aug 08, 2010 9:32 am

Thanks for help me bangonkali, I'm getting a WebCam now I will try again and post my experience.


Mariano.
MIG400
 
Posts: 18
Joined: Sun Aug 01, 2010 8:37 am

Re: Simple VB.Net Video/Webcam Capture

Postby MIG400 » Mon Aug 16, 2010 9:23 am

I'm getting colors now with my webcam, thanks.

Mariano.
MIG400
 
Posts: 18
Joined: Sun Aug 01, 2010 8:37 am


Return to VB Help

Who is online

Users browsing this forum: No registered users and 1 guest