moisdc
February 26, 2011, 15:57:09
Dear colleagues,
I'm trying to capture a video with my DFGUSB with a determinate contrast, brightness, saturation and sharpness.
Then I would like to show in color and in gray this video from opencv.
Also, I would like to save this video from opencv, for example in .avi.
I have a DFGUSB2 connected to my TV and to my laptop by USB, I use IC Control 3.2 and VisualStudio 2008 (vc8). I have windows 7, 32 bits.
Currently, I have not achieved to save the video with opencv. I think that I have missed something in my code.
Thank you in advance
-- Moises Diaz-Cabrera
moisdc@gmail.com
Master's candidate
ps: I attach my current code
#include "stdafx.h"
#include "tisudshl.h"
#include "cv.h"
#include "highgui.h"
#include <math.h>
int _tmain(int argc, _TCHAR* argv[])
{
bool result;
result = DShowLib::InitLibrary( "ISB3200016679");
if (result == false)
{
printf("FAILED\n");
cin.get();
}
Grabber grabber;
setupDeviceFromFile( grabber ); //funcion del IC Control 3.1
grabber.setOverlayBitmapPathPosition( ePP_NONE );
tFrameHandlerSinkPtr pSink = FrameHandlerSink::create( eRGB24, 2 );
pSink->setSnapMode( true );
grabber.setSinkType( pSink );
result = grabber.prepareLive( false );
if (result == false)
{
printf("FAILED\n");
cin.get();
}
FrameTypeInfo info;
pSink->getOutputFrameType( info );
IplImage *img = 0;
IplImage *imgNDG = 0;
CvSize size = cvSize(info.dim.cx,info.dim.cy);
img = cvCreateImage( size, IPL_DEPTH_8U , 3 );
imgNDG = cvCreateImage( size, IPL_DEPTH_8U , 1 );
CvVideoWriter *writer = 0;
int isColor = 1;
int fps = 15; // or 30
writer = cvCreateVideoWriter("output.avi",0,fps,size,isColor);
BYTE* pBuf;
pBuf = new BYTE[info.buffersize];
tMemBufferCollectionPtr pCollection = MemBufferCollection::create( info, 1, &pBuf );
pSink->setMemBufferCollection( pCollection );
grabber.startLive();
while(1)
{
// acquisition image
pSink->snapImages(1);
img->imageData = (char*)pSink->getLastAcqMemBuffer()->getPtr();
cvConvertImage(img,imgNDG,CV_RGB2GRAY);
cvFlip( img, img );
cvShowImage( "Resultat", img );
cvShowImage( "GRAY", imgNDG );
cvWriteFrame(writer,img); //para grabar el frame
char c = cvWaitKey(20);
if( c == 27 ) break;
}
grabber.stopLive();
cvReleaseImage(&img);
cvReleaseImage(&imgNDG);
//cvDestroyWindow("Original Image");
delete [] pBuf;
printf("We are done\n");
cin.get();
return 0;
}
I'm trying to capture a video with my DFGUSB with a determinate contrast, brightness, saturation and sharpness.
Then I would like to show in color and in gray this video from opencv.
Also, I would like to save this video from opencv, for example in .avi.
I have a DFGUSB2 connected to my TV and to my laptop by USB, I use IC Control 3.2 and VisualStudio 2008 (vc8). I have windows 7, 32 bits.
Currently, I have not achieved to save the video with opencv. I think that I have missed something in my code.
Thank you in advance
-- Moises Diaz-Cabrera
moisdc@gmail.com
Master's candidate
ps: I attach my current code
#include "stdafx.h"
#include "tisudshl.h"
#include "cv.h"
#include "highgui.h"
#include <math.h>
int _tmain(int argc, _TCHAR* argv[])
{
bool result;
result = DShowLib::InitLibrary( "ISB3200016679");
if (result == false)
{
printf("FAILED\n");
cin.get();
}
Grabber grabber;
setupDeviceFromFile( grabber ); //funcion del IC Control 3.1
grabber.setOverlayBitmapPathPosition( ePP_NONE );
tFrameHandlerSinkPtr pSink = FrameHandlerSink::create( eRGB24, 2 );
pSink->setSnapMode( true );
grabber.setSinkType( pSink );
result = grabber.prepareLive( false );
if (result == false)
{
printf("FAILED\n");
cin.get();
}
FrameTypeInfo info;
pSink->getOutputFrameType( info );
IplImage *img = 0;
IplImage *imgNDG = 0;
CvSize size = cvSize(info.dim.cx,info.dim.cy);
img = cvCreateImage( size, IPL_DEPTH_8U , 3 );
imgNDG = cvCreateImage( size, IPL_DEPTH_8U , 1 );
CvVideoWriter *writer = 0;
int isColor = 1;
int fps = 15; // or 30
writer = cvCreateVideoWriter("output.avi",0,fps,size,isColor);
BYTE* pBuf;
pBuf = new BYTE[info.buffersize];
tMemBufferCollectionPtr pCollection = MemBufferCollection::create( info, 1, &pBuf );
pSink->setMemBufferCollection( pCollection );
grabber.startLive();
while(1)
{
// acquisition image
pSink->snapImages(1);
img->imageData = (char*)pSink->getLastAcqMemBuffer()->getPtr();
cvConvertImage(img,imgNDG,CV_RGB2GRAY);
cvFlip( img, img );
cvShowImage( "Resultat", img );
cvShowImage( "GRAY", imgNDG );
cvWriteFrame(writer,img); //para grabar el frame
char c = cvWaitKey(20);
if( c == 27 ) break;
}
grabber.stopLive();
cvReleaseImage(&img);
cvReleaseImage(&imgNDG);
//cvDestroyWindow("Original Image");
delete [] pBuf;
printf("We are done\n");
cin.get();
return 0;
}