WebCam的VB.NET图像处理 [英] VB.NET Image Processing from WebCam

查看:106
本文介绍了WebCam的VB.NET图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个古老而不常见的基本人。 1970年,我在大学的Basic学习了一个学期的课程,1992年转到Quick Basic,然后转到Visual Basic。当我想到一些想法时,我这样做是为了一个爱好。

我正在尝试编程一个激光射击范围,可以捕捉短激光射击并在目标位图上画一个洞。使用网络摄像头视频流检测它似乎是一种简单的方法。使用Visual Basic Express 2010,我终于自学了如何从USB摄像头捕获视频并将其显示在Aforge VideoSourcePlayer框中。然而,尽管所有声称这样做是微不足道的,但我无法从此流中提取位图帧以使用过滤器。我已经阅读了文档,并在过去一周内查看了样本,将C#代码翻译成VB.NET等,但我无法让程序识别并捕获视频的位图帧。我将包含下面的操作代码,我只需要从这个视频中获取一系列位图帧的行,这样我就可以使用blob识别。



Form有一个VideoSourcePlayer框和一个PictureBox:

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

推荐答案

你好。



我没有机会使用你正在谈论的这个aforge videosurceplayer盒子,但是,如果你说,当一个帧被接收到一个函数cam_newFrame被调用时,这个函数应该有一个对象作为参数传递给它。此对象应该是您要查找的图像,然后您应该能够将其存储为图像,然后执行过滤器。如果你可以给这个函数的代码,也许我可以帮你更多。
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.


谢谢你的回复。

我似乎无法捕获NewFrame事件。我试过了:



函数cam_newFrame(ByVal sender As Object,ByVal eventArgs As AForge.Video.NewFrameEventArgs)处理cam.NewFrame

从此我得到一个警告,我的功能代码(一个简单的TextBox条目用于测试)不执行:

警告 - 函数''cam_newFrame''没有返回值所有代码路径。使用结果时,可能会在运行时发生空引用异常。



我已经尝试了下面的Sub并再次得不到任何内容PictureBox

Private Sub cam_NewFrame(ByVal sender As Object,ByVal eventArgs As NewFrameEventArgs)

PictureBox1.Image = DirectCast(eventArgs.Frame.Clone(),Bitmap)



我感谢任何指导。
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.


这篇关于WebCam的VB.NET图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆