473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Acessing pointers from capSetCallbackOnFrame (avicap32.dll)

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.
Nov 21 '05 #1
3 8101
Hi,

capCreateCaptureWindow will display the incoming video for you. Here
is an link to an example.

http://www.windowsformsdatagridhelp....6-e5cf2ebb86b6

Ken
--------------------------
"Workgroups" <no*****@domainless.com> wrote in message
news:cK********************@speakeasy.net...
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.

Nov 21 '05 #2
Thanks for the reply Ken. I wish my only goal were to show the preview (my
life would be easier). Thanks to that code in the link I could do that
fairly easily.

What I need to add is a way for the user to adjust R, G, B to modify the
color hue of the video preview. I have created a test app that can
successfully change the color of a normal static (non-cam) image using a
color matrix, so my idea for the cam is to capture each frame from at frame
call back, create an image object from the supplied video buffer, perform a
color matrix transformation on the image (just as I had done in my test app)
and then display the new, colorized image to a picturebox. And this would
occur on every frame callback, so essentially I take data from the raw
stream, filter it, and display my own "colorized preview window" (as it
were) in a picturebox.

I got the preview working, I got the callback "working" (well, it gets
called) but I'm hung up on the logistics of accessing the video buffer
pointer that is supposedly sent to me in a structure (VIDEOHDR) in the
callback function. I've defined the structure like this:

Public Structure VIDEOHDR
Dim lpData As IntPtr
Dim dwBufferLength As Integer
Dim dwBytesUsed As Integer
Dim dwTimeCaptured As Integer
Dim dwUser As Integer
Dim dwFlags As Integer
<VBFixedArray(3)> Dim dwReserved() As Integer
End Structure

But my values in the callback are always this:

lpData = 0
dwBufferLength = 0
dwBytesUsed = 0
dwTimeCaptured = 0
dwUser = 0
dwFlags = 64
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

capCreateCaptureWindow will display the incoming video for you. Here
is an link to an example.

http://www.windowsformsdatagridhelp....6-e5cf2ebb86b6

Ken
--------------------------
"Workgroups" <no*****@domainless.com> wrote in message
news:cK********************@speakeasy.net...
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.

Nov 21 '05 #3
This was a newbie interop problem. The structure passed to my callback
function was not being populated correctly because I was initially
establishing callback by calling a mal-overloaded SendMessage in the first
place:

SendMessage (intPtr, integer, integer, intPtr) as intPtr

with this data:

(PreviewWndHandle, _
WM_CAP_SET_CALLBACK_FRAME, _
0, _
MyDelegate.Method.MethodHandle.GetFunctionPointer)

Someone in the interop ng clued me in that I should create a SendMessage
overload specific for the call:

SendMessage (intPtr, integer, intPtr, MyDelegateType)

Which now I call with similar data,

(PreviewWndHandle, _
WM_CAP_SET_CALLBACK_FRAME, _
IntPtr.Zero, _
MyDelegate)

Passing the delegate itself (instead of using the .GetFunctionPointer method
of the delegate) seems to have made the difference between my callback
function receiving valid and invalid data. Once the callback was setup
properly the structure arrived to my callback populated correctly, and I was
able to create a new managed bitmap from the unmanaged buffer, via the
pointer in the structure:

oBmp = New Bitmap(640, 480, 640 * 3, PixelFormat.Format24bppRgb,
lpVIDEOHDR.lpData)

I draw oBmp onto a 2nd bitmap with an imageAttributes containing a
colorMatrix reflecting user slider values for
r/g/b/brightness/contrast/saturation and essentially create my own
"filtered" preview window. Takes a fair amount of cpu power depending upon
preview rate of the camera, but it's doing it ;-)

"Workgroups" <no*****@domainless.com> wrote in message
news:BL********************@speakeasy.net...
Thanks for the reply Ken. I wish my only goal were to show the preview
(my life would be easier). Thanks to that code in the link I could do
that fairly easily.

What I need to add is a way for the user to adjust R, G, B to modify the
color hue of the video preview. I have created a test app that can
successfully change the color of a normal static (non-cam) image using a
color matrix, so my idea for the cam is to capture each frame from at
frame call back, create an image object from the supplied video buffer,
perform a color matrix transformation on the image (just as I had done in
my test app) and then display the new, colorized image to a picturebox.
And this would occur on every frame callback, so essentially I take data
from the raw stream, filter it, and display my own "colorized preview
window" (as it were) in a picturebox.

I got the preview working, I got the callback "working" (well, it gets
called) but I'm hung up on the logistics of accessing the video buffer
pointer that is supposedly sent to me in a structure (VIDEOHDR) in the
callback function. I've defined the structure like this:

Public Structure VIDEOHDR
Dim lpData As IntPtr
Dim dwBufferLength As Integer
Dim dwBytesUsed As Integer
Dim dwTimeCaptured As Integer
Dim dwUser As Integer
Dim dwFlags As Integer
<VBFixedArray(3)> Dim dwReserved() As Integer
End Structure

But my values in the callback are always this:

lpData = 0
dwBufferLength = 0
dwBytesUsed = 0
dwTimeCaptured = 0
dwUser = 0
dwFlags = 64
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

capCreateCaptureWindow will display the incoming video for you.
Here
is an link to an example.

http://www.windowsformsdatagridhelp....6-e5cf2ebb86b6

Ken
--------------------------
"Workgroups" <no*****@domainless.com> wrote in message
news:cK********************@speakeasy.net...
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.


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: TrustyTif | last post by:
After surfing the google & MSDN for a few days I found an MSDN site that explained how to "new" a multidimensional array in C++...but, I don't know how to use it, for alas, my brain still doesn't...
23
by: Brian | last post by:
I am very new to C# programming and have run into a problem. I apologize for the repost of this article. For some reason, my news reader attached it to an existing thread. First off, I have...
1
by: Philip | last post by:
Hi, first of all I'm new to this whole .net thing so please forgive my ignorance. Now I have a C++ object with me, and I want to be able to call its methods from VB.net. e.g. Foo::Foo { }...
1
by: Daniel Friend | last post by:
Hello, I have a question. I would like to know how I can convert the Video Header to a bitmap in VB .NET I searched everywhere and could not see how to do this. This is as far as I get. I...
9
by: Rick | last post by:
Hi guys!! just one question, can i send pointers from VC++ 2005 to a vc++ 6.0 dll? if it is possible, how can i do this? does VS2005 have rules to send pointers? Regards.
5
by: Dinesh Kumar | last post by:
Hi all I am using VB.NET for a Connector dll in Delphi client and some webservice . can you tell me how to handle pointers in Vb.net which are passed by delphi client as parameters in function...
5
by: Albertas | last post by:
Hello, I'm building a program where i want to use function which is written in C programming language. So I built .dll of it. Functions parameters list looks this: void function(char *input,...
0
by: ramapv | last post by:
Hi all! i have one doubt about void pointers in c with perl ,i have to pass the address to the c function from perl,in c file void argument is there from this it is giving error,runtime error...
1
by: Macias | last post by:
Hi, I'm using avicap32 to capture video from my webcam, but I've a problem. I can cerate preview in ex. in picturebox component, but I need to get image from camera to Bitmap or Image component,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.