Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET image
I am an old and infrequent Basic guy. I took a 1 semester course in Basic in college in 1970, moved to Quick Basic and then Visual Basic in 1992. I do this as a hobby when some idea strikes my fancy.
I am trying to program a Laser Shooting Range that would capture a short laser "shot" and draw a hole on the "target" bitmap. Detecting it with a webcam video stream seems like a straightforward approach. Using Visual Basic Express 2010, I have finally taught myself how to capture the video from a USB camera and display it in an Aforge VideoSourcePlayer box. However, despite all the claims that it is trivial to do so, I cannot extract a bitmap frame from this stream to use the filters. I've read the documentation, and reviewed the samples, translated C# code to VB.NET, etc. over the last week, but I cannot get the program to recognize and capture a bitmap frame of the video. I'll include the operative code below, I just need the lines which get me the series of bitmap frames from this video so I can work with blob identification.
 
Form has a VideoSourcePlayer box and a PictureBox:
'create first video source
Dim cam As New VideoCaptureDevice(videoDevices(cboCameras.SelectedIndex) .MonikerString)
cam.DesiredFrameRate = 10
fMain.VideoSourcePlayer1.VideoSource = cam
fMain.VideoSourcePlayer1.Start()
'when each frame is received, f(cam_newFrame) is called
'cam.NewFrame += New NewFrameEventHandler(AddressOf cam_NewFrame) - This just gives me errors
'Dim img As Bitmap = DirectCast(cam.NewFrame.Clone(), Bitmap) - Displays a 'Blank' picture
Dim img As Bitmap = Bitmap.FromFile("C:\tgtMan-with holes.bmp") - This works, but it's not the video
fMain.PictureBox1.Image = img
Posted 7-Oct-10 9:42am
Edited 7-Oct-10 12:34pm
DaveAuld177.6K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello.
 
I did not have a chance to use this aforge videosurceplayer box that you are talking about, however, if as you say, when a frame is received a function cam_newFrame is called, this function should have an object passed to it as a parameter. This object should be the image you are looking for and then you should be able to store it as an image and then do your filters. if you could give the code for this function maybe i'll be able to help you out more.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thank you for responding.
I cannot seem to "capture" the NewFrame Event. I've tried:
 
"Function cam_newFrame(ByVal sender As Object, ByVal eventArgs As AForge.Video.NewFrameEventArgs) Handles cam.NewFrame"
From this I get a warning and my function code (a simple TextBox entry for testing) does not execute:
"Warning - Function 'cam_newFrame' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used."
 
I've tried the Sub below and again get nothing in my PictureBox
"Private Sub cam_NewFrame(ByVal sender As Object, ByVal eventArgs As NewFrameEventArgs)
PictureBox1.Image = DirectCast(eventArgs.Frame.Clone(), Bitmap)
 
I appreciate any guidance.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 10 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100