X-Git-Url: http://git.maemo.org/git/?p=opencv;a=blobdiff_plain;f=otherlibs%2Fhighgui%2Fcvcap_cmu.cpp;h=6d32df171ce0a84c7f0623c5d6a918066108a698;hp=0dfda394c89876e79bd3ac2e6239836d5e12d8ff;hb=80cd7b93506cc1926882d5fd08a2c74ee9359e29;hpb=467a270adf12425827305759c0c4ea8f5b2b3854 diff --git a/otherlibs/highgui/cvcap_cmu.cpp b/otherlibs/highgui/cvcap_cmu.cpp index 0dfda39..6d32df1 100644 --- a/otherlibs/highgui/cvcap_cmu.cpp +++ b/otherlibs/highgui/cvcap_cmu.cpp @@ -45,42 +45,50 @@ /****************** Capturing video from camera via CMU lib *******************/ -#if defined(HAVE_CMU1394) +#if HAVE_CMU1394 // This firewire capability added by Philip Gruebele (pgruebele@cox.net). // For this to work you need to install the CMU firewire DCAM drivers, // located at http://www-2.cs.cmu.edu/~iwan/1394/. #include "1394camera.h" -typedef struct CvCaptureCAM_CMU +class CvCaptureCAM_CMU : public CvCapture { - CvCaptureVTable* vtable; - int fps; // 0-5 - int mode; // 0-7 - int format; // 0-2, 7 ? - int index; - IplImage * image; - IplImage* rgb_frame; -} -CvCaptureCAM_CMU; +public: + CvCaptureCAM_CMU() + { + index = -1; + image = 0; + } -int icvOpenCAM_CMU(CvCaptureCAM_CMU * capture, int wIndex ); -int icvSetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id, double value ); -void icvCloseCAM_CMU( CvCaptureCAM_CMU* capture ); -int icvGrabFrameCAM_CMU( CvCaptureCAM_CMU* capture ); -IplImage* icvRetrieveFrameCAM_CMU( CvCaptureCAM_CMU* capture ); -double icvGetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id ); -int icvSetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id, double value ); + virtual ~CvCaptureCAM_CMU() + { + close(); + } -static CvCaptureVTable captureCAM_CMU_vtable = -{ - 6, - (CvCaptureCloseFunc)icvCloseCAM_CMU, - (CvCaptureGrabFrameFunc)icvGrabFrameCAM_CMU, - (CvCaptureRetrieveFrameFunc)icvRetrieveFrameCAM_CMU, - (CvCaptureGetPropertyFunc)icvGetPropertyCAM_CMU, - (CvCaptureSetPropertyFunc)icvSetPropertyCAM_CMU, - (CvCaptureGetDescriptionFunc)0 + virtual bool open(int cameraId); + virtual void close(); + virtual double getProperty(int); + virtual bool setProperty(int, double); + virtual bool grabFrame(); + virtual IplImage* retrieveFrame(); + +protected: + C1394Camera* camera(); + CvSize getSize(); + int getDepth(); + int getNChannels(); + + bool setVideoSize(int, int); + bool setMode(int mode); + bool setFrameRate(int rate); + bool setFormat(int format); + + int fps; // 0-5 + int mode; // 0-7 + int format; // 0-2, 7 ? + int index; + IplImage* image; }; // CMU 1394 camera stuff. @@ -119,122 +127,140 @@ C1394Camera *CMU_theCamera = 0; #define CV_CAP_IEEE1394_SIZE_1600X1200 6 // given color, size, output format - // 1 16 444 422 411 RGB -char CV_CAP_IEEE1394_FORMAT[7][6] = { {-1, -1, 0, -1, -1, -1}, // 160x120 - {-1, -1, -1, 0, -1, -1}, // 320x240 - { 0, 0, -1, 0, 0, 0}, // 640x480 - { 1, 1, -1, 1, -1, 1}, // 800x600 - { 1, 1, -1, 1, -1, 1}, // 1024x768 - { 2, 2, -1, 2, -1, 2}, // 1280x960 - { 2, 2, -1, 2, -1, 2}}; // 1600x1200 +// 1 16 444 422 411 RGB +static char CV_CAP_IEEE1394_FORMAT[7][6] = +{ + {-1, -1, 0, -1, -1, -1}, // 160x120 + {-1, -1, -1, 0, -1, -1}, // 320x240 + { 0, 0, -1, 0, 0, 0}, // 640x480 + { 1, 1, -1, 1, -1, 1}, // 800x600 + { 1, 1, -1, 1, -1, 1}, // 1024x768 + { 2, 2, -1, 2, -1, 2}, // 1280x960 + { 2, 2, -1, 2, -1, 2} // 1600x1200 +}; + // given color, size, output corresponding mode -char CV_CAP_IEEE1394_MODE[7][6] = { {-1, -1, 0, -1, -1, -1}, // 160x120 - {-1, -1, -1, 1, -1, -1}, // 320x240 - { 5, 6, -1, 3, 2, 4}, // 640x480 - { 2, 6, -1, 0, -1, 1}, // 800x600 - { 5, 7, -1, 3, -1, 4}, // 1024x768 - { 2, 6, -1, 0, -1, 1}, // 1280x960 - { 5, 7, -1, 3, -1, 4}}; // 1600x1200 +static char CV_CAP_IEEE1394_MODE[7][6] = +{ + {-1, -1, 0, -1, -1, -1}, // 160x120 + {-1, -1, -1, 1, -1, -1}, // 320x240 + { 5, 6, -1, 3, 2, 4}, // 640x480 + { 2, 6, -1, 0, -1, 1}, // 800x600 + { 5, 7, -1, 3, -1, 4}, // 1024x768 + { 2, 6, -1, 0, -1, 1}, // 1280x960 + { 5, 7, -1, 3, -1, 4} // 1600x1200 +}; + // given format, mode, return COLOR -char CV_CAP_IEEE1394_COLOR[2][8] = { { CV_CAP_IEEE1394_COLOR_YUV444, - CV_CAP_IEEE1394_COLOR_YUV422, - CV_CAP_IEEE1394_COLOR_YUV411, - CV_CAP_IEEE1394_COLOR_YUV422, - CV_CAP_IEEE1394_COLOR_RGB, - CV_CAP_IEEE1394_COLOR_MONO, - CV_CAP_IEEE1394_COLOR_MONO16 }, - { CV_CAP_IEEE1394_COLOR_YUV422, - CV_CAP_IEEE1394_COLOR_RGB, - CV_CAP_IEEE1394_COLOR_MONO, - CV_CAP_IEEE1394_COLOR_YUV422, - CV_CAP_IEEE1394_COLOR_RGB, - CV_CAP_IEEE1394_COLOR_MONO, - CV_CAP_IEEE1394_COLOR_MONO16, - CV_CAP_IEEE1394_COLOR_MONO16 } }; +static char CV_CAP_IEEE1394_COLOR[2][8] = +{ + { + CV_CAP_IEEE1394_COLOR_YUV444, + CV_CAP_IEEE1394_COLOR_YUV422, + CV_CAP_IEEE1394_COLOR_YUV411, + CV_CAP_IEEE1394_COLOR_YUV422, + CV_CAP_IEEE1394_COLOR_RGB, + CV_CAP_IEEE1394_COLOR_MONO, + CV_CAP_IEEE1394_COLOR_MONO16 + }, + { + CV_CAP_IEEE1394_COLOR_YUV422, + CV_CAP_IEEE1394_COLOR_RGB, + CV_CAP_IEEE1394_COLOR_MONO, + CV_CAP_IEEE1394_COLOR_YUV422, + CV_CAP_IEEE1394_COLOR_RGB, + CV_CAP_IEEE1394_COLOR_MONO, + CV_CAP_IEEE1394_COLOR_MONO16, + CV_CAP_IEEE1394_COLOR_MONO16 + } +}; // convert frame rate to suitable enum /*static int icvFrameRateToIndex_CMU(double framerate){ - if(framerate > 30) return CV_CAP_IEEE1394_FPS_60; - else if(framerate > 15) return CV_CAP_IEEE1394_FPS_30; - else if(framerate > 7.5) return CV_CAP_IEEE1394_FPS_15; - else if(framerate > 3.75) return CV_CAP_IEEE1394_FPS_7_5; - else if(framerate > 1.875) return CV_CAP_IEEE1394_FPS_3_75; - return CV_CAP_IEEE1394_FPS_1_875; + if(framerate > 30) return CV_CAP_IEEE1394_FPS_60; + else if(framerate > 15) return CV_CAP_IEEE1394_FPS_30; + else if(framerate > 7.5) return CV_CAP_IEEE1394_FPS_15; + else if(framerate > 3.75) return CV_CAP_IEEE1394_FPS_7_5; + else if(framerate > 1.875) return CV_CAP_IEEE1394_FPS_3_75; + return CV_CAP_IEEE1394_FPS_1_875; }*/ #if _MSC_VER >= 1200 #pragma comment(lib,"1394camera.lib") #endif +C1394Camera* CvCaptureCAM_CMU::camera() +{ + return CMU_theCamera && index >= 0 ? &CMU_theCamera[index] : 0; +} + // return the size of the image -CvSize icvGetSize_CMU( C1394Camera * cmucam ){ - //int format = cmucam->GetVideoFormat(); - //int mode = cmucam->GetVideoMode(); - - // irrelvant to depth - // if( format > 1 ) format=1; - - // for YUV, should we return a weirdly sized image? - //switch(CV_CAP_IEEE1394_COLOR[format][mode]){ - //case CV_CAP_IEEE1394_COLOR_MONO16: - // return cvSize(cmucam->m_width*2, cmucam->m_height); - //default: - // return cvSize(cmucam->m_width, cmucam->m_height); - //} - unsigned long width = 0, height = 0; - cmucam->GetVideoFrameDimensions( &width, &height ); - return cvSize((int)width, (int)height); +CvSize CvCaptureCAM_CMU::getSize() +{ + C1394Camera* cmucam = camera(); + unsigned long width = 0, height = 0; + cmucam->GetVideoFrameDimensions( &width, &height ); + return cvSize((int)width, (int)height); } // return the opencv depth flag corresponding to the camera format -int icvGetDepth_CMU( C1394Camera * cmucam ){ - int format = cmucam->GetVideoFormat(); - int mode = cmucam->GetVideoMode(); - - // TODO - if( format==7 ) { - assert(0); - } - // irrelvant to depth - if( format > 1 ) format=1; - - if(CV_CAP_IEEE1394_COLOR[format][mode]==CV_CAP_IEEE1394_COLOR_MONO16){ - return IPL_DEPTH_16S; - } - return IPL_DEPTH_8U; +int CvCaptureCAM_CMU::getDepth() +{ + C1394Camera* cmucam = camera(); + int format = cmucam->GetVideoFormat(); + int mode = cmucam->GetVideoMode(); + + // TODO + if( format==7 ) { + assert(0); + return 1; + } + // irrelvant to depth + if( format > 1 ) + format = 1; + + if( CV_CAP_IEEE1394_COLOR[format][mode]==CV_CAP_IEEE1394_COLOR_MONO16 ) + return IPL_DEPTH_16S; + + return IPL_DEPTH_8U; } // return the number of channels for camera -int icvGetNChannels_CMU( C1394Camera * cmucam ){ +int CvCaptureCAM_CMU::getNChannels() +{ + C1394Camera* cmucam = camera(); + int format = cmucam->GetVideoFormat(); + int mode = cmucam->GetVideoMode(); - int format = cmucam->GetVideoFormat(); - int mode = cmucam->GetVideoMode(); - - if( format==7 ){ - assert(0); - } - - // irrelvant to nchannels - if( format > 1 ) format=1; - - switch(CV_CAP_IEEE1394_COLOR[format][mode]){ - case CV_CAP_IEEE1394_COLOR_RGB: - return 3; - case CV_CAP_IEEE1394_COLOR_MONO: - case CV_CAP_IEEE1394_COLOR_MONO16: - return 1; - case CV_CAP_IEEE1394_COLOR_YUV422: - case CV_CAP_IEEE1394_COLOR_YUV444: - case CV_CAP_IEEE1394_COLOR_YUV411: - return 3; - default: - ; - } - return -1; + if( format==7 ){ + assert(0); + return 1; + } + + // irrelvant to nchannels + if( format > 1 ) + format = 1; + + switch(CV_CAP_IEEE1394_COLOR[format][mode]){ + case CV_CAP_IEEE1394_COLOR_RGB: + return 3; + case CV_CAP_IEEE1394_COLOR_MONO: + case CV_CAP_IEEE1394_COLOR_MONO16: + return 1; + case CV_CAP_IEEE1394_COLOR_YUV422: + case CV_CAP_IEEE1394_COLOR_YUV444: + case CV_CAP_IEEE1394_COLOR_YUV411: + return 3; + default: + ; + } + return -1; } -int icvOpenCAM_CMU(CvCaptureCAM_CMU * capture, int index ) +bool CvCaptureCAM_CMU::open( int _index ) { + close(); + // if first time, then allocate all available cameras if( CMU_numCameras == 0 ) { @@ -252,7 +278,7 @@ int icvOpenCAM_CMU(CvCaptureCAM_CMU * capture, int index ) // we have one pin per camera CMU_numCameras = CMU_theCamera[0].GetNumberCameras(); - // allocate remaining cameras + // allocate remaining cameras for(int i = 1; i < CMU_numCameras && i=0 && !found_format; rate--){ - for (int color=CV_CAP_IEEE1394_COLOR_RGB; color>=0 && !found_format; color--){ - for (int size=CV_CAP_IEEE1394_SIZE_1600X1200; size>=0 && !found_format; size--){ - int format = CV_CAP_IEEE1394_FORMAT[size][color]; - int mode = CV_CAP_IEEE1394_MODE[size][color]; - if (format!=-1 && mode!=-1 && - CMU_theCamera[index].HasVideoFrameRate(format,mode,rate)){ - CMU_theCamera[index].SetVideoFormat(format); - CMU_theCamera[index].SetVideoMode(mode); - CMU_theCamera[index].SetVideoFrameRate(rate); - found_format = (CMU_theCamera[index].StartImageAcquisition() == CAM_SUCCESS); - } - } - } - } + // set initial format -- try to pick best frame rate first, then color, then size + bool found_format = false; + for (int rate=5; rate>=0 && !found_format; rate--) + { + for (int color=CV_CAP_IEEE1394_COLOR_RGB; color>=0 && !found_format; color--) + { + for (int size=CV_CAP_IEEE1394_SIZE_1600X1200; size>=0 && !found_format; size--) + { + int format = CV_CAP_IEEE1394_FORMAT[size][color]; + int mode = CV_CAP_IEEE1394_MODE[size][color]; + if (format!=-1 && mode!=-1 && + CMU_theCamera[_index].HasVideoFrameRate(format,mode,rate)) + { + CMU_theCamera[_index].SetVideoFormat(format); + CMU_theCamera[_index].SetVideoMode(mode); + CMU_theCamera[_index].SetVideoFrameRate(rate); + found_format = (CMU_theCamera[_index].StartImageAcquisition() == CAM_SUCCESS); + } + } + } + } - // try format 7 - if(!found_format){ - CMU_theCamera[index].SetVideoFormat(7); - CMU_theCamera[index].SetVideoMode(0); - if(CMU_theCamera[index].StartImageAcquisition() != CAM_SUCCESS){ - // no format found - throw 9; - } - } + // try format 7 + if(!found_format){ + CMU_theCamera[_index].SetVideoFormat(7); + CMU_theCamera[_index].SetVideoMode(0); + if(CMU_theCamera[_index].StartImageAcquisition() != CAM_SUCCESS){ + // no format found + throw 9; + } + } - // allocate image frame - capture->image = cvCreateImage(icvGetSize_CMU(&(CMU_theCamera[index])), - icvGetDepth_CMU(&(CMU_theCamera[index])), - icvGetNChannels_CMU(&(CMU_theCamera[index]))); - if (capture->image) - { - // successfully activated camera - capture->index = index; //CMU_numActiveCameras; - CMU_numActiveCameras++; - CMU_useCameraFlags[index] = true; - } - } - catch ( int ) - { - return 0; - } + index = _index; + size = getSize(); + // allocate image frame + image = cvCreateImage( size, 8, 3 ); + cvZero(image); - return 1; + // successfully activated camera + CMU_numActiveCameras++; + CMU_useCameraFlags[_index] = true; + } + catch ( int ) + { + return false; + } + + return true; } -void icvCloseCAM_CMU( CvCaptureCAM_CMU* capture ) +void CvCaptureCAM_CMU::close() { - if( capture && capture->image ) - { - cvReleaseImage( &capture->image ); - CMU_theCamera[capture->index].StopImageAcquisition(); - CMU_useCameraFlags[capture->index] = false; - CMU_numActiveCameras--; - - if (!CMU_numActiveCameras) - { - delete[] CMU_theCamera; - CMU_theCamera = 0; - CMU_numCameras = 0; - } - } + C1394Camera* cmucam = camera(); + if( cmucam ) + { + cvReleaseImage( &image ); + cmucam->StopImageAcquisition(); + CMU_useCameraFlags[index] = false; + index = -1; + + if( --CMU_numActiveCameras == 0 ) + { + delete[] CMU_theCamera; + CMU_theCamera = 0; + CMU_numCameras = 0; + } + } } -int icvGrabFrameCAM_CMU( CvCaptureCAM_CMU* capture ) +bool CvCaptureCAM_CMU::grabFrame() { - return capture->image && CMU_theCamera && - CMU_theCamera[capture->index].AcquireImage() == CAM_SUCCESS; + C1394Camera* cmucam = camera(); + return cmucam ? cmucam->AcquireImage() == CAM_SUCCESS : false; } -static void swapRedBlue(IplImage * im){ +/*static void swapRedBlue(IplImage * im) +{ uchar * ptr = (uchar *) im->imageData; uchar t; for(int i=0; iheight; i++){ @@ -377,146 +409,143 @@ static void swapRedBlue(IplImage * im){ ptr+=3; } } -} +}*/ -IplImage* icvRetrieveFrameCAM_CMU( CvCaptureCAM_CMU* capture ) +IplImage* CvCaptureCAM_CMU::retrieveFrame() { - if( capture->image && CMU_theCamera ) - { - //capture->image->imageData = (char *) CMU_theCamera[capture->index].GetRawData(0); - CMU_theCamera[capture->index].getRGB((unsigned char*)capture->image->imageData, - capture->image->imageSize); - swapRedBlue( capture->image ); - return capture->image; - } - return 0; + C1394Camera* cmucam = camera(); + if( !cmucam ) + return 0; + cmucam->getRGB((uchar*)image->imageData, image->imageSize); + cvConvertImage( image, image, CV_CVTIMG_SWAP_RB ); + return image; } -double icvGetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id ) +double CvCaptureCAM_CMU::getProperty( int property_id ) { - switch( property_id ) - { - case CV_CAP_PROP_FRAME_WIDTH: - return capture->image->width; - case CV_CAP_PROP_FRAME_HEIGHT: - return capture->image->height; - case CV_CAP_PROP_FPS: - return CMU_theCamera[capture->index].GetVideoFrameRate(); - case CV_CAP_PROP_MODE: - return CMU_theCamera[capture->index].GetVideoMode(); - case CV_CAP_PROP_FORMAT: - return CMU_theCamera[capture->index].GetVideoFormat(); - } - return 0; + C1394Camera* cmucam = camera(); + if( !cmucam ) + return 0; + switch( property_id ) + { + case CV_CAP_PROP_FRAME_WIDTH: + return image->width; + case CV_CAP_PROP_FRAME_HEIGHT: + return image->height; + case CV_CAP_PROP_FPS: + return cmucam->GetVideoFrameRate(); + case CV_CAP_PROP_MODE: + return cmucam->GetVideoMode(); + case CV_CAP_PROP_FORMAT: + return cmucam->GetVideoFormat(); + } + return 0; } -static int icvSetVideoSize( CvCaptureCAM_CMU* capture, int, int) { - if (capture==0) return 0; - // change to closest size - return -1; +bool CvCaptureCAM_CMU::setVideoSize(int, int) +{ + return false; } -static int icvSetMode(CvCaptureCAM_CMU * capture, int mode){ - int format = CMU_theCamera[capture->index].GetVideoFormat(); - if(mode < 0 || mode > 7){ - return -1; - } - if(CMU_theCamera[capture->index].HasVideoMode(format, mode)){ - CMU_theCamera[capture->index].StopImageAcquisition(); - CMU_theCamera[capture->index].SetVideoMode(mode); - CMU_theCamera[capture->index].StartImageAcquisition(); - return 0; - } - return -1; +bool CvCaptureCAM_CMU::setMode(int mode) +{ + int format; + C1394Camera* cmucam = camera(); + if( !cmucam ) + return false; + format = cmucam->GetVideoFormat(); + if( mode < 0 || mode > 7 || !cmucam->HasVideoMode(format, mode)) + return false; + cmucam->StopImageAcquisition(); + cmucam->SetVideoMode(mode); + cmucam->StartImageAcquisition(); + return true; } -static int icvSetFrameRate(CvCaptureCAM_CMU * capture, int rate){ - int mode = CMU_theCamera[capture->index].GetVideoMode(); - int format = CMU_theCamera[capture->index].GetVideoFormat(); - if(rate < 0 || rate > 5){ - return -1; - } - if(CMU_theCamera[capture->index].HasVideoFrameRate(format, mode, rate)){ - CMU_theCamera[capture->index].StopImageAcquisition(); - CMU_theCamera[capture->index].SetVideoFrameRate(rate); - CMU_theCamera[capture->index].StartImageAcquisition(); - return 0; - } - return -1; +bool CvCaptureCAM_CMU::setFrameRate(int rate) +{ + int format, mode; + C1394Camera* cmucam = camera(); + if( !cmucam ) + return false; + mode = cmucam->GetVideoMode(); + format = cmucam->GetVideoFormat(); + if( rate < 0 || rate > 5 || !cmucam->HasVideoFrameRate(format, mode, rate) ) + return false; + cmucam->StopImageAcquisition(); + cmucam->SetVideoFrameRate(rate); + cmucam->StartImageAcquisition(); + return true; } -static int icvSetFormat(CvCaptureCAM_CMU * capture, int format){ - if(format < 0 || format > 2){ - return -1; - } - if(CMU_theCamera[capture->index].HasVideoFormat(format)){ - CMU_theCamera[capture->index].StopImageAcquisition(); - CMU_theCamera[capture->index].SetVideoFormat(format); - CMU_theCamera[capture->index].StartImageAcquisition(); - return 0; - } - return -1; +bool CvCaptureCAM_CMU::setFormat(int format) +{ + C1394Camera* cmucam = camera(); + if( !cmucam ) + return false; + if( format < 0 || format > 2 || !cmucam->HasVideoFormat(format) ) + return false; + cmucam->StopImageAcquisition(); + cmucam->SetVideoFormat(format); + cmucam->StartImageAcquisition(); + return true; } -int icvSetPropertyCAM_CMU( CvCaptureCAM_CMU* capture, int property_id, double value ){ - int retval = -1; - int ival= cvRound(value); - switch (property_id) { - case CV_CAP_PROP_FRAME_WIDTH: - case CV_CAP_PROP_FRAME_HEIGHT: - { - int width, height; - if (property_id == CV_CAP_PROP_FRAME_WIDTH) { - width = ival; - height = width*3/4; - } - else { - height = ival; - width = height*4/3; - } - retval = icvSetVideoSize(capture, width, height); - } - break; - case CV_CAP_PROP_FPS: - retval =icvSetFrameRate(capture, ival); - break; - case CV_CAP_PROP_MODE: - retval =icvSetMode(capture, ival); - break; - case CV_CAP_PROP_FORMAT: - retval =icvSetFormat(capture, ival); - break; - } +bool CvCaptureCAM_CMU::setProperty( int property_id, double value ) +{ + bool retval = false; + int ival = cvRound(value); + C1394Camera* cmucam = camera(); + if( !cmucam ) + return false; + + switch (property_id) { + case CV_CAP_PROP_FRAME_WIDTH: + case CV_CAP_PROP_FRAME_HEIGHT: + { + int width, height; + if (property_id == CV_CAP_PROP_FRAME_WIDTH) + { + width = ival; + height = width*3/4; + } + else { + height = ival; + width = height*4/3; + } + retval = setVideoSize(width, height); + } + break; + case CV_CAP_PROP_FPS: + retval = setFrameRate(ival); + break; + case CV_CAP_PROP_MODE: + retval = setMode(ival); + break; + case CV_CAP_PROP_FORMAT: + retval = setFormat(ival); + break; + } - // resize image if its not the right size anymore - CvSize size = icvGetSize_CMU( &(CMU_theCamera[capture->index]) ); - int depth = icvGetDepth_CMU( &(CMU_theCamera[capture->index]) ); - int nch = icvGetNChannels_CMU( &(CMU_theCamera[capture->index]) ); - if(size.width != capture->image->width || - size.height != capture->image->height || - depth != capture->image->depth || - nch != capture->image->nChannels ) - { - cvReleaseImage(&capture->image); - capture->image = cvCreateImage(size, depth, nch); - } - return retval; + // resize image if its not the right size anymore + CvSize size = getSize(); + if( !image || image->width != size.width || image->height != size.height ) + { + cvReleaseImage( &image ); + image = cvCreateImage( size, 8, 3 ); + } + return retval; } -CvCapture * cvCaptureFromCAM_CMU (int index) +CvCapture * cvCreateCameraCapture_CMU (int index) { - CvCaptureCAM_CMU* capture = (CvCaptureCAM_CMU*)cvAlloc( sizeof(*capture)); - memset( capture, 0, sizeof(*capture)); - capture->vtable = &captureCAM_CMU_vtable; - - if( icvOpenCAM_CMU( capture, index )) - return (CvCapture*)capture; - - cvReleaseCapture( (CvCapture**)&capture ); - return 0; + CvCaptureCAM_CMU* capture = new CvCaptureCAM_CMU; + if( !capture->open(index) ) + return capture; + delete capture; + return 0; } #endif // CMU #endif // WIN32 -