PDA

View Full Version : How to use an image/ Draw cover the live video



webmice
April 23, 2004, 20:47:39
I try to use CClientDC to draw something on the live picture , but i will covered by the live picture at next frame.

If I want to draw a transprance square on the live picture , How can I do it ??

Please Help !!!

webmice
April 24, 2004, 19:28:56
I wan to keep the pixel data , so I don't wan t to use Overlay Bitmap

Stefan Geissler
April 26, 2004, 08:40:17
See here:
http://www.theimagingsourceforums.com/showthread.php?s=&threadid=315583

Stefan Geissler
April 26, 2004, 09:13:20
Hello Webmice,

After reading all of our threads again, i nearly understand, what you want to do. You want to draw graphic over the live video without overwriting the pixel under the graphics but also without changing your overlay. Your problem is, that the next frame of the live video deletes your overlay.
Well, the solution is to control the drawing of the live video and the overlay on your own. The OverlayBitmap of IC Imaging Control is just copied on the live video frames. Therefore it can be saved in bitmaps or AVI files too. If it is copied on the live video, the information under the overlay graphics is overwritten.
To avoid this, you must perform some steps.
First of all, IC Imaging Control does not draw the live video. You can perform this by call following functions:

C++:
grabber.startlive( false );

Visual Basic (VB):
ICImagingControl1.LiveDisplay = False
ICImagingControl1.LiveStart.

Next step is to draw the live video frames. Therefore IC Imaging Control must call a callback function (C++) or fire an event (VB). In C++ we use a GrabberListener derived class. This class is added to the listeners of the grabber. For example:
grabber.addListener (&cListener);
I will explain this class later.
In VB IC Imaging Control fires the ImageAvailable event. To make IC Imaging Control call the Clistener::frameReady or the ICImagingControl1.ImageAvailable event, some more preparations are to be performed:

C++:
m_Grabber.setSinkType( FrameGrabberSink( FrameGrabberSink::tFrameGrabberMode::eGRAB, DShowLib::eRGB24 ) );
m_pMemBuffColl = m_Grabber.newMemBufferCollection( 5 );
m_Grabber.setActiveMemBufferCollection( m_pMemBuffColl );
m_Grabber.setHWND( cVideoWindow.mHWnd);
m_Grabber.startLive(false);
// The CvideoWindow is a window, where to display the frames in. This can be a normal CStatic window or a CView...


VB:
ICImagingControl1.LiveDisplay = False
ICImagingControl1.ImageRingBufferSize = 5
ICImagingControl1.LiveCaptureContinuous = True
ICImagingControl1.LiveStart.

Now, we have IC Imaging Control prepared to call a function (C++) or an event (VB) for each new frame. The next step is to display the frames:
C++:
We have created a class CListener (i have send you several examples of this class). The Clistener::frameReady() method is called when the grabber delivers a new frame. To display this frame now, we need to blit on the window, we want to use as draw window. Therefore your CListener class could use the grabber::getHWND() method to retrieve the window to draw in. Now the method for drawing the live video must be implemented:


void CListener::DrawBuffer( Grabber& grabber, smart_ptr<MemBuffer> pBuffer)
{
if( m_pDrawCWnd != NULL)
{
if( pBuffer != 0 )
{
HDC hDC = GetDC( grabber.getHWND());

smart_ptr<BITMAPINFOHEADER> pInf = pBuffer->getBitmapInfoHeader();
void* pBuf = pBuffer->getPtr();
int nLines = SetDIBitsToDevice(hDC,// Handle to the device
0,
0,
pInf->biWidth, // Source rectangle width
pInf->biHeight, // Source rectangle height
0, // X-coordinate of lower-left corner of the source rect
0,// Y-coordinate of lower-left corner of the source rect
0, // First scan line in array
pInf->biHeight, // Number of scan lines
pBuffer->getPtr(), // Modified address of array with DIB bits
reinterpret_cast<LPBITMAPINFO>( &*pInf ),
DIB_RGB_COLORS// RGB or palette indices
);

' Perform here your own drawings, lines, circles etc.

ReleaseDC(grabber.getHWND());
}
}
}

This method is called from the frameReady() method.


VB:


Private Sub ICImagingControl1_ImageAvailable(ByVal BufferIndex As Long)
Picture1.Picture = ICImagingControl1.ImageBuffers.Item(BufferIndex).P icture
' Perform here your own drawings, lines, circles etc.
End Sub

We use a PictureBox to display the Live video frames.

After the live video image has been drawn on the window or PictureBox, the overlay graphics must be drawn again. Therefore you application must know the coordinates of your drawings. On each frame, this drawing must be done again.
I hope, this answers your questions. If not, please let me know whether you work with Visual Basic or C++.

webmice
May 4, 2004, 20:26:21
OK I Understand your point

1) I use C++
1) Creat the framready() it's work fine !
2) Creat DrawBuffer as your code , the error as follow

C:\PROGRAM FILES\THE IMAGING SOURCE EUROPE GMBH\IC IMAGING CONTROL 1.41\Vision\Listener.cpp(233) : error C2065: 'm_pDrawCWnd' : undeclared identifier
C:\PROGRAM FILES\THE IMAGING SOURCE EUROPE GMBH\IC IMAGING CONTROL 1.41\Vision\Listener.cpp(257) : error C2660: 'ReleaseDC' : function does not take 1 parameters

question :

a) What is m_pDrawCwnd
b) ReleaseDC error ??
c) can you create some sample of these ??

Stefan Geissler
May 5, 2004, 08:36:08
Heelo webmice.

m_pDrawWindow should be the windows handle, in that the live video should be drawn. This handle must set by your application. You my exchange this by grabber.getHWND().

The ReleaseDC() should be
ReleaseDC(grabber.getHWND(),hDC);

The parameter could be vice versa, i did not test this. Please have a look into MSDN for Release DC.

webmice
May 6, 2004, 20:47:30
I create a circle & keep the pixel data

the problem is I still cannot draw the circle without filled .

I checked in MSDN that "SelectStockObject" can do the transprance fill , but I can't use it in Listener.cpp

How can I do ??

webmice
May 6, 2004, 21:02:28
In Listener.cpp can I jump to View.cpp or Doc.cpp to do something ??

Stefan Geissler
May 7, 2004, 13:56:56
You should pass the window handle of your CView window to the listener. Then could could this handle for your drawings.

For drawing circles, elipses, arcs etc, please refer to the MSDN platform SDK.

webmice
May 9, 2004, 13:45:05
After do the drawing , the picture will update to 4900 frame or more . then stop live again , Why this Happen ????

webmice
May 9, 2004, 18:29:23
my project have the frame number print of the live pictuer as your sample , the problem is when the project run till to 4989 or more frame number show , the display of the live picture will stop !!!!

I checked & move the window , the update frame number will appear , but without continue update the screen , after I move the window again , the latest update fram Number will show again . What Problem of that ???

Stefan Geissler
May 10, 2004, 09:27:40
Webmice,

Please zip your project and send it to support@imagingcontrol.com so i can correct it. I think, this would be the bettest way.

webmice
May 19, 2004, 17:44:19
Thank you For your Help !!!

But After I check again in 3 ~ 5 min the problem still happen as before !!

webmice
May 19, 2004, 17:57:56
If I don't draw anything , that's fine & no problem, If I draw something , the drawing line will ture to black color & the Live image Stop . as the problem before within 2 min.

Stefan Geissler
May 21, 2004, 11:10:02
Hello,

i checked the program i have send to you and found no problems.

What you describe sounds for a resource problem. Each GDI object that is created by your program must be deleted after it is no longer in use. Constructs like


SelectObject( hDC, CreatePen(PS_SOLID,1,RGB(255,0,0));


are deadly to every programm, because the created Pen is not deleted and occupies a resource handle.

webmice
May 27, 2004, 11:46:10
After install GDI+ , All the problem gone & can do the alpha drawing tooo !!!

Great !!!!!