PDA

View Full Version : How To Display The Processed Buffer



624989202
August 10, 2011, 12:25:21
Hi,
I have processed the Membuffer in the FrameReady of the Listenner.Now I want to display the result buffer,but I can't find the method from the User's Guide.Could you give me some advice?

Michael Kirmse
August 11, 2011, 09:31:42
Dear 624989202,

to display the processed buffer, please refer to the code sample below. You can create a sample on your own, by building a new IC Dialog Application with the Visual Studio project wizard and select "Do image processing" and "show processed image" on the options page of the wizard.



//////////////////////////////////////////////////////////////////////////
// Callback handler.
//////////////////////////////////////////////////////////////////////////

void CListener::frameReady( Grabber& param, smart_ptr<MemBuffer> pBuffer, DWORD FrameNumber)
{
pBuffer->lock();
DoImageProcessing( pBuffer );
DrawBuffer(pBuffer);
pBuffer->unlock();
}

//////////////////////////////////////////////////////////////////////////
// Draw the image buffer into the DrawCWnd.
//////////////////////////////////////////////////////////////////////////

void CListener::DrawBuffer( smart_ptr<MemBuffer> pBuffer)
{
if( m_pDrawCWnd != NULL)
{
if( pBuffer != 0 )
{
CDC *pDC = m_pDrawCWnd->GetDC();
pDC->SetStretchBltMode(COLORONCOLOR);

smart_ptr<BITMAPINFOHEADER> pInf = pBuffer->getBitmapInfoHeader();



int nLines = StretchDIBits( pDC->GetSafeHdc(),// Handle to the device
0,
0,
m_WindowSize.cx, // Dest. rectangle width.
m_WindowSize.cy, // Dest. rectangle height.
0, // X-coordinate of lower-left corner of the source rect.
0, // Y-coordinate of lower-left corner of the source rect.
pInf->biWidth, // Source rectangle width.
pInf->biHeight, // Number of scan lines.
pBuffer->getPtr(), // Modified address of array with DIB bits.
reinterpret_cast<LPBITMAPINFO>( &*pInf ), // Address of structure with bitmap info.
DIB_RGB_COLORS, // RGB or palette indices.
SRCCOPY
);
m_pDrawCWnd->ReleaseDC(pDC);
}
}
}

624989202
August 11, 2011, 17:36:36
Thanks,Michael!

624989202
August 12, 2011, 06:30:20
Now I meet a new question.I have three camera,and in the program I have set three grabber pointers and three listeners fasten on each grabber. Then I add the code into the listener class as Michael suggested.The listeners fastened on grabber2 and grabber3 can work well,and we can see the processed pictures display on screen ,however the listener fastened on grabber1 cannot display on the screen.What should I do?
Ps:The three listeners and the three grabbers are equipollence.

Michael Kirmse
August 12, 2011, 09:53:40
Dear 624989202,
I am very sorry, but I do not really understand your problem. Would you please create a sample project that reproduces the issue and send it to me?

624989202
August 12, 2011, 13:12:40
Dear Michael,
I have posted the sample codes in the attachment.Waiting for your answer.

624989202
August 12, 2011, 13:31:10
Dear Michael,
I have posted the sample codes in the attachment.Waiting for your answer.1410

Michael Kirmse
August 12, 2011, 14:31:24
Dear 624989202,

what cameras do you have and how do you connect them to your computer?

624989202
August 12, 2011, 17:20:14
The cameras are DMK 31BG03.H.The GigE cameras.They work well when we just use the function startlive(true);.

Stefan Geissler
August 15, 2011, 13:17:02
Hello

I had a look into your sample source code. I think, you want to display the three live videos in one window. Therefore, you pass the window handle of your view window to the listener, which stores it in the n_pDrawWindow member. However, in your CameraSet.CPP you also pass the same handle to the grabber object. This will cause many flickering, therefore, I suggest to remove the part


pGrabber->setHWND( m_hWnd );

//ͼλ
pGrabber->setDefaultWindowPosition(false);
pGrabber->setWindowPosition(x,y);
// Set the new window size
pGrabber->setWindowSize(lWidth, lHeight);

Since you display the video images in the Listener, you do following at the same position:


if( pGrabber->isDevValid() )
{
pGrabber->startLive(false);

//
m_DefaultSet.SaveDefaultCcdData(pGrabber,pfilename );

return true;
}


You will encounter problems, if you write in the DC of the drawwindow from different positions at the same point of time. That means, you have three listeners writing on the DC at the same time. This is not recommended and can cause problems.

You may do not draw tne video image in the Listener. You may setup a timer with 15ms intervall. In the timer event you check with m_pSinkx->getLastAcqMemBuffer()->getLastAcqMemBuffer() whether the index in the ringbuffer has changed. This indicates a new image. If so, you lock the image buffer and draw it, as you did in the Listener. You proceed in sequence with your three grabber objects. This makes sure, that you do not have double access to the windows's DC.

Pleasy try to implement this first.

624989202
August 16, 2011, 05:57:37
Thank you for your advice.I will have a try.

Best regards!