如何捕捉USB数码摄像头的每帧图像
我要使用usb数码摄像头捕捉一个光点的运动轨迹,并在电脑上实时显示,请做过类似工作的朋友帮帮忙啊
[最优解释]
看看我的blog
VC中实现VFW的时时视频捕捉
[其他解释]
使用VFW进行视频捕获程序开发的基本思路是:
1、声明API函数和消息常数
(1)声明两个消息处理函数
Declare Function SendMsgN Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SendMsgS Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
注意:这两个函数实质上是同一个函数即SendMessageA函数。其声明原型为:
Declare Function SendMsgS Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
这里为了对函数的最后一个参数分别使用不同的数据类型,改为了两个函数进行声明。
(2)声明创建视频捕获窗口的函数
Declare Function capCreateCaptureWindowA Lib "avicap32.dll" (ByVal Nm As String, ByVal dwS As Long, ByVal x As Long, ByVal y As Long, ByVal nW As Long, ByVal nH As Integer, ByVal hPW As Long, ByVal nID As Long) As Long
其中各参数的含义如下:
Nm:指定视频捕获窗口的名称。
dwS:指定视频捕获窗口的显示风格。各风格常数可通过API浏览器查询。一般指定为WS_CAPTION Or WS_VISIBLE Or WS_CHILD。
x、y:指定视频捕获窗口的左上角在容器中的坐标。
nW、nH:指定视频捕获窗口的宽度和高度。
hPW:指定视频捕获窗口的容器的句柄。任何具有hWnd属性的对象均可以作为视频捕获窗口的容器,例如:Form、TextBox、PictureBox,等等。
nID:指定视频捕获窗口ID。一般可设置为0。
(3)声明消毁窗口的函数
Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long
(4)声明视频处理相关的常数
Const WM_CAP_START = &H400
Const WM_CAP_GET_CAPSTREAMPTR = WM_CAP_START + 1
Const WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START + 2
Const WM_CAP_SET_CALLBACK_STATUS = WM_CAP_START + 3
Const WM_CAP_SET_CALLBACK_YIELD = WM_CAP_START + 4
Const WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5
Const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START + 6
Const WM_CAP_SET_CALLBACK_WAVESTREAM = WM_CAP_START + 7
Const WM_CAP_GET_USER_DATA = WM_CAP_START + 8
Const WM_CAP_SET_USER_DATA = WM_CAP_START + 9
Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
Const WM_CAP_DRIVER_GET_NAME = WM_CAP_START + 12
Const WM_CAP_DRIVER_GET_VERSION = WM_CAP_START + 13
Const WM_CAP_DRIVER_GET_CAPS = WM_CAP_START + 14
Const WM_CAP_FILE_SET_CAPTURE_FILE = WM_CAP_START + 20
Const WM_CAP_FILE_GET_CAPTURE_FILE = WM_CAP_START + 21
Const WM_CAP_FILE_ALLOCATE = WM_CAP_START + 22
Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
Const WM_CAP_FILE_SET_INFOCHUNK = WM_CAP_START + 24
Const WM_CAP_FILE_SAVEDIB = WM_CAP_START + 25
Const WM_CAP_EDIT_COPY = WM_CAP_START + 30
Const WM_CAP_SET_AUDIOFORMAT = WM_CAP_START + 35
Const WM_CAP_GET_AUDIOFORMAT = WM_CAP_START + 36
Const WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41
Const WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42
Const WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43
Const WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44
Const WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45
Const WM_CAP_DLG_VIDEOCOMPRESSION = WM_CAP_START + 46
Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Const WM_CAP_SET_OVERLAY = WM_CAP_START + 51
Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Const WM_CAP_SET_SCALE = WM_CAP_START + 53
Const WM_CAP_GET_STATUS = WM_CAP_START + 54
Const WM_CAP_SET_SCROLL = WM_CAP_START + 55
Const WM_CAP_GRAB_FRAME = WM_CAP_START + 60
Const WM_CAP_GRAB_FRAME_NOSTOP = WM_CAP_START + 61
Const WM_CAP_SEQUENCE = WM_CAP_START + 62
Const WM_CAP_SEQUENCE_NOFILE = WM_CAP_START + 63
Const WM_CAP_SET_SEQUENCE_SETUP = WM_CAP_START + 64
Const WM_CAP_GET_SEQUENCE_SETUP = WM_CAP_START + 65
Const WM_CAP_SET_MCI_DEVICE = WM_CAP_START + 66
Const WM_CAP_GET_MCI_DEVICE = WM_CAP_START + 67
Const WM_CAP_STOP = WM_CAP_START + 68
Const WM_CAP_ABORT = WM_CAP_START + 69
Const WM_CAP_SINGLE_FRAME_OPEN = WM_CAP_START + 70
Const WM_CAP_SINGLE_FRAME_CLOSE = WM_CAP_START + 71
Const WM_CAP_SINGLE_FRAME = WM_CAP_START + 72
Const WM_CAP_PAL_OPEN = WM_CAP_START + 80
Const WM_CAP_PAL_SAVE = WM_CAP_START + 81
Const WM_CAP_PAL_PASTE = WM_CAP_START + 82
Const WM_CAP_PAL_AUTOCREATE = WM_CAP_START + 83
Const WM_CAP_PAL_MANUALCREATE = WM_CAP_START + 84
'// Following added post VFW 1.1
Const WM_CAP_SET_CALLBACK_CAPCONTROL = WM_CAP_START + 85
Const WM_CAP_END = WM_CAP_SET_CALLBACK_CAPCONTROL
2、创建并初始化视频捕获窗口
'创建捕获窗口。变量capWnd为公共变量,用于返回捕获窗口的句柄。
capWnd = capCreateCaptureWindowA("XBW", &H50000000, 0, 0, 300, 240, Me.hWnd, 0)
SendMsgN capWnd, &H40A, 0, 0 '连接设备
SendMsgN capWnd, &H434, 66, 0 '设置预览速度
SendMsgN capWnd, &H432, 1, 0 '开始预览模式
3、捕获视频。
SendMsgS capWnd, &H414, 0, "c:\x.avi" '设置待保存的AVI文件
SendMsgN capWnd, &H43E, 0, 0 '捕获视频流
4、终止视频捕获。
SendMsgS capWnd, &H417, 0, "c:\x.avi" '保存视频和音频
5、抓取单帧图像。
SendMsgS capWnd, &H419, 0, "c:\x.bmp" '抓图、单帧保存
6、消毁视频窗口。
SendMsgN capWnd, &H40B, 0, 0 '断开设备
DestroyWindow capWnd '销毁视窗
7、对话框调用。
控制设置对话框:SendMsgN capWnd, &H42A, 0, 0
视频格式对话框:SendMsgN capWnd, &H429, 0, 0
压缩对话框:SendMsgN capWnd, &H42E, 0, 0
[其他解释]
关注
[其他解释]
up
[其他解释]
该回复于2009-10-19 10:46:36被版主删除
[其他解释]
摄像头送出来的就是每秒15幅BMP图片(15帧/秒),你要做的对这些图片进行模式识别,建议参考《Visual C++数字图像模式识别技术及工程实践》
[其他解释]
要捕捉一秒内的每帧图像,不能太复杂吧,不然电脑哪处理的过来?
[其他解释]
一秒内有多少帧图像?