tiggerwang 2008-3-3 03:02
视频捕捉
请教高手,我是菜鸟
我用有一个webcamera, 运行了视频,有了视频显示,我想每隔几秒把视频的桢抓出来,判断桢中红颜色的位置
怎么做? 谢谢
tiggerwang 2008-3-3 05:44
视频捕捉
:)我的代码:引用AVICAP
我先把视频缓冲的内容读到内存,然后把内存的数据写成bitmap,看看我写的对吗?
Public Function MyFrameCheck(hDestBmp As Long) As Long
Dim VideoHeader As VIDEOHDR
Dim VideoData() As Byte
Dim X As Integer, y As Integer
Dim tDBmpInfo As BITMAP
Dim dBits() As Byte
'//Fill VideoHeader with data at lpVHdr
RtlMoveMemory VarPtr(VideoHeader), lpvhdr, Len(VideoHeader)
'// Make room for data
ReDim VideoData(VideoHeader.dwBytesUsed)
'//Copy data into the memory array
RtlMoveMemory VarPtr(VideoData(0)), VideoHeader.lpData, VideoHeader.dwBytesUsed
'get bitmap
Call GetObject(hDestBmp, Len(tDBmpInfo), tDBmpInfo)
Call SetBitmapBits(hDestBmp, tDBmpInfo.bmWidthBytes * tDBmpInfo.bmHeight, VarPtr(VideoData(0)))
Image1.Picture.Handle = hDestBmp
Dim c1 As Long 'Picture1的RGB颜色
Dim r As Boolean 'R分量
Dim g As Boolean
Dim b As Boolean
For X = 0 To tDBmpInfo.bmWidth - 1
For y = 0 To tDBmpInfo.bmHeight - 1
c1 = Image1.Point(X, y)
r = c1 And &HFF
g = (c1 And 65280) / 256
b = (c1 And &HFF0000) / 65536
If r = True And g = False And b = False Then
Label1.Caption = X
Label2.Caption = y
Exit For
End If
Next
Next
End Function
tiggerwang 2008-3-5 08:55
thanks
我知道了,从视频读出来得就是颜色值,我没必要再转换成BMP格式了,直接操作就可以了,希望同行借鉴
Nothing 2008-3-5 16:13
因为图像会模糊一点,可能会有一些变色,应当取一个色值范围而不是一个值。