Applied XIMEA path (by Marian Zajko) with multiple changes #2054

This commit is contained in:
Andrey Kamaev 2012-06-26 11:47:49 +00:00
parent e9e66e5796
commit f9418853a0

View File

@ -1,8 +1,8 @@
#include "precomp.hpp"
#include "xiApi.h"
#include "xiExt.h"
#include "m3Api.h"
/**********************************************************************************/
@ -22,7 +22,7 @@ public:
protected:
void init();
void errMsg(char* msg, int errNum);
void errMsg(const char* msg, int errNum);
IplImage* frame;
HANDLE hmv;
@ -53,6 +53,7 @@ void CvCaptureCAM_XIMEA::init()
{
xiGetNumberDevices( &numDevices);
hmv = NULL;
memset(&image, 0, sizeof(XI_IMG));
}
@ -72,30 +73,50 @@ bool CvCaptureCAM_XIMEA::open( int wIndex )
}
// always use auto exposure/gain
xiSetParamInt( hmv, XI_PRM_AEAG, 1);
mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1);
if(mvret != XI_OK) goto error;
// always use auto white ballance
xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1);
mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1);
if(mvret != XI_OK) goto error;
xiGetParamInt( hmv, XI_PRM_WIDTH, &width);
xiGetParamInt( hmv, XI_PRM_HEIGHT, &height);
mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width);
if(mvret != XI_OK) goto error;
mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height);
if(mvret != XI_OK) goto error;
// default image format RGB24
xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24);
format = XI_RGB24;
mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, format);
if(mvret != XI_OK) goto error;
// allocate frame buffer for RGB24 image
frame = cvCreateImage(cvSize( width, height), IPL_DEPTH_8U, 3);
//default capture timeout 10s
timeout = 10000;
mvret = xiStartAcquisition(hmv);
if(mvret != XI_OK)
{
errMsg("StartAcquisition XI_DEVICE failed", mvret);
goto error;
}
return true;
error:
xiCloseDevice(hmv);
hmv = NULL;
return false;
}
/**********************************************************************************/
void CvCaptureCAM_XIMEA::close()
{
xiStopAcquisition(hmv);
xiCloseDevice(hmv);
hmv = NULL;
}
@ -104,13 +125,21 @@ void CvCaptureCAM_XIMEA::close()
bool CvCaptureCAM_XIMEA::grabFrame()
{
int mvret = XI_OK;
image.size = sizeof(XI_IMG);
if((mvret = xiGetImage( hmv, timeout, &image)) != XI_OK)
int mvret = xiGetImage( hmv, timeout, &image);
if(mvret == MM40_ACQUISITION_STOPED)
{
xiStartAcquisition(hmv);
mvret = xiGetImage(hmv, timeout, &image);
}
if(mvret != XI_OK)
{
errMsg("Error during GetImage", mvret);
return false;
}
return true;
}
@ -119,7 +148,7 @@ bool CvCaptureCAM_XIMEA::grabFrame()
IplImage* CvCaptureCAM_XIMEA::retrieveFrame(int)
{
// update cvImage after format has changed
if( image.width != width || image.height != height || image.frm != format)
if( (int)image.width != width || (int)image.height != height || image.frm != (XI_IMG_FORMAT)format)
{
cvReleaseImage(&frame);
switch( image.frm)
@ -128,6 +157,8 @@ IplImage* CvCaptureCAM_XIMEA::retrieveFrame(int)
case XI_MONO16 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_16U, 1); break;
case XI_RGB24 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 3); break;
case XI_RGB32 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 4); break;
default :
return frame;
}
// update global image format
format = image.frm;
@ -142,6 +173,7 @@ IplImage* CvCaptureCAM_XIMEA::retrieveFrame(int)
case XI_MONO16 : memcpy( frame->imageData, image.bp, image.width*image.height*sizeof(WORD)); break;
case XI_RGB24 : memcpy( frame->imageData, image.bp, image.width*image.height*3); break;
case XI_RGB32 : memcpy( frame->imageData, image.bp, image.width*image.height*sizeof(DWORD)); break;
default: break;
}
return frame;
}
@ -186,6 +218,7 @@ double CvCaptureCAM_XIMEA::getProperty( int property_id )
case CV_CAP_PROP_XI_AG_MAX_LIMIT : xiGetParamFloat( hmv, XI_PRM_AG_MAX_LIMIT, &fval); return fval;
case CV_CAP_PROP_XI_AEAG_LEVEL : xiGetParamInt( hmv, XI_PRM_AEAG_LEVEL, &ival); return ival;
case CV_CAP_PROP_XI_TIMEOUT : return timeout;
}
return 0;
}
@ -202,14 +235,20 @@ bool CvCaptureCAM_XIMEA::setProperty( int property_id, double value )
switch(property_id)
{
// OCV parameters
case CV_CAP_PROP_FRAME_WIDTH : mvret = xiSetParamInt( hmv, XI_PRM_WIDTH, ival); break;
case CV_CAP_PROP_FRAME_HEIGHT : mvret = xiSetParamInt( hmv, XI_PRM_HEIGHT, ival); break;
case CV_CAP_PROP_FRAME_WIDTH : mvret = xiSetParamInt( hmv, XI_PRM_WIDTH, ival);
if(mvret == XI_OK) width = ival;
break;
case CV_CAP_PROP_FRAME_HEIGHT : mvret = xiSetParamInt( hmv, XI_PRM_HEIGHT, ival);
if(mvret == XI_OK) height = ival;
break;
case CV_CAP_PROP_FPS : mvret = xiSetParamFloat( hmv, XI_PRM_FRAMERATE, fval); break;
case CV_CAP_PROP_GAIN : mvret = xiSetParamFloat( hmv, XI_PRM_GAIN, fval); break;
case CV_CAP_PROP_EXPOSURE : mvret = xiSetParamInt( hmv, XI_PRM_EXPOSURE, ival); break;
// XIMEA camera properties
case CV_CAP_PROP_XI_DOWNSAMPLING : mvret = xiSetParamInt( hmv, XI_PRM_DOWNSAMPLING, ival); break;
case CV_CAP_PROP_XI_DATA_FORMAT : mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, ival); break;
case CV_CAP_PROP_XI_DATA_FORMAT : mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, ival);
if(mvret == XI_OK) format = ival;
break;
case CV_CAP_PROP_XI_OFFSET_X : mvret = xiSetParamInt( hmv, XI_PRM_OFFSET_X, ival); break;
case CV_CAP_PROP_XI_OFFSET_Y : mvret = xiSetParamInt( hmv, XI_PRM_OFFSET_Y, ival); break;
case CV_CAP_PROP_XI_TRG_SOURCE : mvret = xiSetParamInt( hmv, XI_PRM_TRG_SOURCE, ival); break;
@ -243,11 +282,15 @@ bool CvCaptureCAM_XIMEA::setProperty( int property_id, double value )
/**********************************************************************************/
void CvCaptureCAM_XIMEA::errMsg(char* msg, int errNum)
void CvCaptureCAM_XIMEA::errMsg(const char* msg, int errNum)
{
#if defined WIN32 || defined _WIN32
char buf[512];
sprintf( buf, "%s : %d\n", msg, errNum);
OutputDebugString(buf);
#else
fprintf(stderr, "%s : %d\n", msg, errNum);
#endif
}
/**********************************************************************************/