PDA

View Full Version : A problem about Listener and framready.



kid
August 10, 2007, 06:33:40
Hello.
I am a new user of IC Imaging......
My purpose is to do some image processing in every frame which gotten from camera . To do this, it sounds that there two ways , the first is that make a directshow filter,do the image processing in the filter, but I have no time to study filter ( it seems difficult....) . The second way can be this, make a timer, get 20(or more) frames in one second, then do some image processing in every frame, then draw it . I think the second way is not efficient, because it have to a lot work, in one second, it have to get the image, do the image processing, and draw it . Am I right ? And there are another way ?

The second question. I read the sample of the callback, and I changed it in soma place, first, I defined a
CD *pDC in the in CListener, and changed
int nLines = SetDIBitsToDevice( pDC->GetSafeHdc().........., and in put a IDC_Image1 (IDC_Static) in the dialog, in the ButtonClick
CWnd * pWndImage1;
CDC *pDCImage1;
pWndImage1=GetDlgItem(IDC_Image1);
pDCImage1=pWndImage1->GetDC();
pListener->pDC=pDCImage1;

So, I think it can draw every frame on the dialog, where is the error ? Thank you for your help.




void CImgProceDlg::OnBnClickedButton1()
{
m_pGrabber = new DShowLib::Grabber();
ASSERT( m_pGrabber );
m_pGrabber->showDevicePage();
if( m_pGrabber->isDevValid() )
{
m_pGrabber->setHWND( m_hWnd );
CListener *pListener = new CListener();

DShowLib::FrameHandlerSink::tFHSPtr m_pSink;
m_pSink = DShowLib::FrameHandlerSink::create(DShowLib::eRGB2 4, 5 );
m_pSink->setSnapMode( true );
m_pGrabber->setSinkType( m_pSink );

CWnd * pWndImage1;
CDC *pDCImage1;
pWndImage1=GetDlgItem(IDC_Image1);
pDCImage1=pWndImage1->GetDC();
pListener->pDC=pDCImage1;

m_pGrabber->addListener( pListener, GrabberListener::eFRAMEREADY|GrabberListener::eOVE RLAYCALLBACK );
m_pGrabber->startLive();
}

}

in CListener
I definded
public:
CDC * pDC;


void CListener::frameReady( Grabber& param, smart_ptr<MemBuffer> pBuffer, DWORD currFrame)
{
pBuffer->lock();

smart_ptr<BITMAPINFOHEADER> pInf = pBuffer->getBitmapInfoHeader();
BYTE *pPixel = pBuffer->getPtr();
unsigned int iBytecount = pInf->biWidth * pInf->biBitCount / 8 * pInf->biHeight;

for( unsigned int i = 0; i < iBytecount; i++)
{
*pPixel = (BYTE)(0xFF - (*pPixel));
pPixel++;
}
TRACE("aaaa\n");
// And we can do another image processing in here...... The image of output is the result of image processing, so we can do the image processing in every frame without using a timer to get n frames in one second..... Am I right?


int nLines = SetDIBitsToDevice( pDC->GetSafeHdc(),// 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 ), // Address of structure with bitmap info
DIB_RGB_COLORS // RGB or palette indices
);



pBuffer->unlock();

}

kid
August 10, 2007, 06:48:26
In this thread http://www.theimagingsourceforums.com/showthread.php?t=313424
m_Grabber.setSinkType( DShowLib::FrameGrabberSink(
DShowLib::FrameGrabberSink::tFrameGrabberMode::eGR AB, DShowLib::eRGB24 ) );

Mr.Stefan said
The "eGRAB" parameter
in the sink type makes the grabber grab every frame and call the frameReady()
method of your Grabber instance. . In my sample , I used

DShowLib::FrameHandlerSink::tFHSPtr m_pSink;
m_pSink = DShowLib::FrameHandlerSink::create(DShowLib::eRGB2 4, 5 );
m_pSink->setSnapMode( true );
m_pGrabber->setSinkType( m_pSink ); .
Because when I used

m_Grabber.setSinkType( DShowLib::FrameGrabberSink(
DShowLib::FrameGrabberSink::tFrameGrabberMode::eGR AB, DShowLib::eRGB24 ) );

it has the error:


error C2664: 'DShowLib::Grabber::setSinkType' : cannot convert parameter 1 from 'DShowLib::FrameGrabberSink' to 'const smart_ptr<TType> &'

Dose this make the frameready don't work ?

kid
August 10, 2007, 12:44:02
Is anyone here ? I am waiting for your answer. Thank you very much.

Sascha Schmidt
August 10, 2007, 13:48:21
Hallo Kid,

The following way is the correct in order to add a Listener to the grabber:


// Add the CListener object to the the Grabber object.
pListener = new CListener();
m_cGrabber.addListener( pListener, GrabberListener::eFRAMEREADY );

// Create the frame handler sink
smart_ptr<FrameHandlerSink> pSink = FrameHandlerSink::create( eRGB24, 5 );

// Automatically copy every frame to the sink and call CListener::frameReady().
m_pSink->setSnapMode( false );

// Apply the sink to the grabber.
m_cGrabber.setSinkType( pSink );

Also, please download the attached realtime image processing sample. I hope this will solve your problem.

kid
August 10, 2007, 15:25:17
Thank you Sascha, the file is very helpful for me ,thank you so much. And I have a new problem, if I open a .avi file, are there also a Listener? In other word, can it do the image processing like abover way? If not, which way can be used, and also, can you send me a simple sample like above sample.

Thank you very much all time.

Sascha Schmidt
August 10, 2007, 15:52:53
Hallo kid,

Do you want to open an finished .avi and process its frames?
This is unfortunately not supported by IC Imaging Control.

Or do you want to save the processed frames into a .avi?
This can be done by creating a MediaStreamSink and adding a framefilter to the Sink.
This is described in the documentation in MediaStreamSink::create.

Alternatively you also can do the image processing with a listener, like above and use the AVIfile.dll to create a .avi and the frames.
The Avifile.dll provieds the following functions:


bool AVICreate(String FileName, int Width, int Height, short BitCount,int FrameRate, String CompressorOptionsFileName );
byte AVIAddFrame( IntPtr Data );
void AVIClose();
byte SaveCompressorOptions( String CompressorOptionsFileName );
byte LoadCompressorOptions( String CompressorOptionsFileName );

kid
August 10, 2007, 16:10:17
Yes, I want to open an finished .avi and process its frames.
I am sorry to hear that is not supported by IC Imaging Control.
Thank you for your file.;)