W
Workgroups
I'm writing a piece of video software, sort of like a webcam, that's meant
to show a preview on the screen from any WDM capable cam. I want to give
the user RGB sliders, and process each frame by running it through a color
matrix before it's displayed on the screen.
So far I've succesfully created a preview window and established a
capSetCallbackOnFrame callback function that fires every time a new frame of
video is available from the camera. So now I need to copy the video buffer
(image) I vicariously receive a pointer to in the callback function into an
image, transform the image's color w/ a color matrix and then paint the
colorized image to some control (like a picturebox, probably).
But I'm stumped when it comes to "doing something" with the data that's
coming back from capSetCallbackOnFrame. It's a pointer to a structure, and
one of the elements of the structure contains the pointer to the video
buffer. The documentation for this is really hard to come by, although
there is a popular VB6 example of this floating around that I've been using
for a guide that looks like this:
Function MyFrameCallback(ByVal lwnd As Long, ByVal lpVHdr As Long) As Long
Dim VideoHeader As VIDEOHDR
Dim VideoData() As Byte
RtlMoveMemory VarPtr(VideoHeader), lpVHdr, Len(VideoHeader)
ReDim VideoData(VideoHeader.dwBytesUsed)
RtlMoveMemory VarPtr(VideoData(0)), VideoHeader.lpData,
VideoHeader.dwBytesUsed
End Function
The VIDEOHDR structure looks like this:
Type VIDEOHDR
lpData As Long 'address of video buffer
dwBufferLength As Long 'size, in bytes, of the Data buffer
dwBytesUsed As Long
dwTimeCaptured As Long
dwUser As Long
dwFlags As Long
dwReserved(3) As Long '// reserved; do not use
End Type
I've tried to reporduce this in .NET but I haven't been too successful so
far... I've tried to use Marshal.Copy and Marshal.PtrToStructure, to copy
the data referenced at lpVHdr into it's appropriate structure format on the
managed side, but I don't think I'm doing it right; my structure ends up
with what I'm pretty sure is erroneous data; all the values are 0 except
for dwFlags = 64, so... "something" is getting copied in there but it's not
correct. I am at a loss as to how to get that video buffer turned into an
image object.
to show a preview on the screen from any WDM capable cam. I want to give
the user RGB sliders, and process each frame by running it through a color
matrix before it's displayed on the screen.
So far I've succesfully created a preview window and established a
capSetCallbackOnFrame callback function that fires every time a new frame of
video is available from the camera. So now I need to copy the video buffer
(image) I vicariously receive a pointer to in the callback function into an
image, transform the image's color w/ a color matrix and then paint the
colorized image to some control (like a picturebox, probably).
But I'm stumped when it comes to "doing something" with the data that's
coming back from capSetCallbackOnFrame. It's a pointer to a structure, and
one of the elements of the structure contains the pointer to the video
buffer. The documentation for this is really hard to come by, although
there is a popular VB6 example of this floating around that I've been using
for a guide that looks like this:
Function MyFrameCallback(ByVal lwnd As Long, ByVal lpVHdr As Long) As Long
Dim VideoHeader As VIDEOHDR
Dim VideoData() As Byte
RtlMoveMemory VarPtr(VideoHeader), lpVHdr, Len(VideoHeader)
ReDim VideoData(VideoHeader.dwBytesUsed)
RtlMoveMemory VarPtr(VideoData(0)), VideoHeader.lpData,
VideoHeader.dwBytesUsed
End Function
The VIDEOHDR structure looks like this:
Type VIDEOHDR
lpData As Long 'address of video buffer
dwBufferLength As Long 'size, in bytes, of the Data buffer
dwBytesUsed As Long
dwTimeCaptured As Long
dwUser As Long
dwFlags As Long
dwReserved(3) As Long '// reserved; do not use
End Type
I've tried to reporduce this in .NET but I haven't been too successful so
far... I've tried to use Marshal.Copy and Marshal.PtrToStructure, to copy
the data referenced at lpVHdr into it's appropriate structure format on the
managed side, but I don't think I'm doing it right; my structure ends up
with what I'm pretty sure is erroneous data; all the values are 0 except
for dwFlags = 64, so... "something" is getting copied in there but it's not
correct. I am at a loss as to how to get that video buffer turned into an
image object.