Commit 8eb6decb authored by Andrew Senin's avatar Andrew Senin

Fixed Ximea cameras support

parent 98f6a4a6
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
# #
# Created: 5 Aug 2011 by Marian Zajko (marian.zajko@ximea.com) # Created: 5 Aug 2011 by Marian Zajko (marian.zajko@ximea.com)
# Updated: 25 June 2012 by Igor Kuzmin (parafin@ximea.com) # Updated: 25 June 2012 by Igor Kuzmin (parafin@ximea.com)
# Updated: 22 October 2012 by Marian Zajko (marian.zajko@ximea.com)
# #
set(XIMEA_FOUND) set(XIMEA_FOUND)
...@@ -19,10 +20,14 @@ if(WIN32) ...@@ -19,10 +20,14 @@ if(WIN32)
# Try to find the XIMEA API path in registry. # Try to find the XIMEA API path in registry.
GET_FILENAME_COMPONENT(XIMEA_PATH "[HKEY_CURRENT_USER\\Software\\XIMEA\\CamSupport\\API;Path]" ABSOLUTE) GET_FILENAME_COMPONENT(XIMEA_PATH "[HKEY_CURRENT_USER\\Software\\XIMEA\\CamSupport\\API;Path]" ABSOLUTE)
if(EXISTS XIMEA_PATH) if(EXISTS ${XIMEA_PATH})
set(XIMEA_FOUND 1) set(XIMEA_FOUND 1)
# set LIB folders # set LIB folders
if(CMAKE_CL_64)
set(XIMEA_LIBRARY_DIR "${XIMEA_PATH}/x64")
else()
set(XIMEA_LIBRARY_DIR "${XIMEA_PATH}/x86") set(XIMEA_LIBRARY_DIR "${XIMEA_PATH}/x86")
endif()
else() else()
set(XIMEA_FOUND 0) set(XIMEA_FOUND 0)
endif() endif()
...@@ -39,4 +44,3 @@ endif() ...@@ -39,4 +44,3 @@ endif()
mark_as_advanced(FORCE XIMEA_FOUND) mark_as_advanced(FORCE XIMEA_FOUND)
mark_as_advanced(FORCE XIMEA_PATH) mark_as_advanced(FORCE XIMEA_PATH)
mark_as_advanced(FORCE XIMEA_LIBRARY_DIR) mark_as_advanced(FORCE XIMEA_LIBRARY_DIR)
\ No newline at end of file
...@@ -179,7 +179,11 @@ if(HAVE_XIMEA) ...@@ -179,7 +179,11 @@ if(HAVE_XIMEA)
if(XIMEA_LIBRARY_DIR) if(XIMEA_LIBRARY_DIR)
link_directories(${XIMEA_LIBRARY_DIR}) link_directories(${XIMEA_LIBRARY_DIR})
endif() endif()
if(CMAKE_CL_64)
list(APPEND HIGHGUI_LIBRARIES m3apiX64)
else()
list(APPEND HIGHGUI_LIBRARIES m3api) list(APPEND HIGHGUI_LIBRARIES m3api)
endif()
endif(HAVE_XIMEA) endif(HAVE_XIMEA)
if(HAVE_FFMPEG) if(HAVE_FFMPEG)
......
...@@ -20,18 +20,17 @@ public: ...@@ -20,18 +20,17 @@ public:
virtual IplImage* retrieveFrame(int); virtual IplImage* retrieveFrame(int);
virtual int getCaptureDomain() { return CV_CAP_XIAPI; } // Return the type of the capture object: CV_CAP_VFW, etc... virtual int getCaptureDomain() { return CV_CAP_XIAPI; } // Return the type of the capture object: CV_CAP_VFW, etc...
protected: private:
void init(); void init();
void errMsg(const char* msg, int errNum); void errMsg(const char* msg, int errNum);
void resetCvImage();
int getBpp();
IplImage* frame; IplImage* frame;
HANDLE hmv; HANDLE hmv;
DWORD numDevices; DWORD numDevices;
XI_IMG image;
int width;
int height;
int format;
int timeout; int timeout;
XI_IMG image;
}; };
/**********************************************************************************/ /**********************************************************************************/
...@@ -80,15 +79,16 @@ bool CvCaptureCAM_XIMEA::open( int wIndex ) ...@@ -80,15 +79,16 @@ bool CvCaptureCAM_XIMEA::open( int wIndex )
mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1); mvret = xiSetParamInt( hmv, XI_PRM_AUTO_WB, 1);
if(mvret != XI_OK) goto error; if(mvret != XI_OK) goto error;
mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width); // default image format RGB24
mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24);
if(mvret != XI_OK) goto error; if(mvret != XI_OK) goto error;
mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height); int width = 0;
mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width);
if(mvret != XI_OK) goto error; if(mvret != XI_OK) goto error;
// default image format RGB24 int height = 0;
format = XI_RGB24; mvret = xiGetParamInt( hmv, XI_PRM_HEIGHT, &height);
mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, format);
if(mvret != XI_OK) goto error; if(mvret != XI_OK) goto error;
// allocate frame buffer for RGB24 image // allocate frame buffer for RGB24 image
...@@ -103,10 +103,10 @@ bool CvCaptureCAM_XIMEA::open( int wIndex ) ...@@ -103,10 +103,10 @@ bool CvCaptureCAM_XIMEA::open( int wIndex )
errMsg("StartAcquisition XI_DEVICE failed", mvret); errMsg("StartAcquisition XI_DEVICE failed", mvret);
goto error; goto error;
} }
return true; return true;
error: error:
errMsg("Open XI_DEVICE failed", mvret);
xiCloseDevice(hmv); xiCloseDevice(hmv);
hmv = NULL; hmv = NULL;
return false; return false;
...@@ -116,18 +116,19 @@ error: ...@@ -116,18 +116,19 @@ error:
void CvCaptureCAM_XIMEA::close() void CvCaptureCAM_XIMEA::close()
{ {
if(hmv) if(frame)
{ cvReleaseImage(&frame);
xiStopAcquisition(hmv); xiStopAcquisition(hmv);
xiCloseDevice(hmv); xiCloseDevice(hmv);
hmv = NULL; hmv = NULL;
}
} }
/**********************************************************************************/ /**********************************************************************************/
bool CvCaptureCAM_XIMEA::grabFrame() bool CvCaptureCAM_XIMEA::grabFrame()
{ {
memset(&image, 0, sizeof(XI_IMG));
image.size = sizeof(XI_IMG); image.size = sizeof(XI_IMG);
int mvret = xiGetImage( hmv, timeout, &image); int mvret = xiGetImage( hmv, timeout, &image);
...@@ -151,31 +152,18 @@ bool CvCaptureCAM_XIMEA::grabFrame() ...@@ -151,31 +152,18 @@ bool CvCaptureCAM_XIMEA::grabFrame()
IplImage* CvCaptureCAM_XIMEA::retrieveFrame(int) IplImage* CvCaptureCAM_XIMEA::retrieveFrame(int)
{ {
// update cvImage after format has changed // update cvImage after format has changed
if( (int)image.width != width || (int)image.height != height || image.frm != (XI_IMG_FORMAT)format) resetCvImage();
{
cvReleaseImage(&frame);
switch( image.frm)
{
case XI_MONO8 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 1); break;
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;
width = image.width;
height = image.height;
}
// copy pixel data // copy pixel data
switch( image.frm) switch( image.frm)
{ {
case XI_MONO8 : memcpy( frame->imageData, image.bp, image.width*image.height); break; case XI_MONO8 :
case XI_MONO16 : memcpy( frame->imageData, image.bp, image.width*image.height*sizeof(WORD)); break; case XI_RAW8 : memcpy( frame->imageData, image.bp, image.width*image.height); break;
case XI_RGB24 : memcpy( frame->imageData, image.bp, image.width*image.height*3); break; case XI_MONO16 :
case XI_RGB32 : memcpy( frame->imageData, image.bp, image.width*image.height*sizeof(DWORD)); break; case XI_RAW16 : memcpy( frame->imageData, image.bp, image.width*image.height*sizeof(WORD)); break;
case XI_RGB24 :
case XI_RGB_PLANAR : memcpy( frame->imageData, image.bp, image.width*image.height*3); break;
case XI_RGB32 : memcpy( frame->imageData, image.bp, image.width*image.height*4); break;
default: break; default: break;
} }
return frame; return frame;
...@@ -183,6 +171,35 @@ IplImage* CvCaptureCAM_XIMEA::retrieveFrame(int) ...@@ -183,6 +171,35 @@ IplImage* CvCaptureCAM_XIMEA::retrieveFrame(int)
/**********************************************************************************/ /**********************************************************************************/
void CvCaptureCAM_XIMEA::resetCvImage()
{
int width = 0, height = 0, format = 0;
xiGetParamInt( hmv, XI_PRM_WIDTH, &width);
xiGetParamInt( hmv, XI_PRM_HEIGHT, &height);
xiGetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, &format);
if( (int)image.width != width || (int)image.height != height || image.frm != (XI_IMG_FORMAT)format)
{
if(frame) cvReleaseImage(&frame);
frame = NULL;
switch( image.frm)
{
case XI_MONO8 :
case XI_RAW8 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_8U, 1); break;
case XI_MONO16 :
case XI_RAW16 : frame = cvCreateImage(cvSize( image.width, image.height), IPL_DEPTH_16U, 1); break;
case XI_RGB24 :
case XI_RGB_PLANAR : 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;
}
}
cvZero(frame);
}
/**********************************************************************************/
double CvCaptureCAM_XIMEA::getProperty( int property_id ) double CvCaptureCAM_XIMEA::getProperty( int property_id )
{ {
if(hmv == NULL) if(hmv == NULL)
...@@ -238,20 +255,14 @@ bool CvCaptureCAM_XIMEA::setProperty( int property_id, double value ) ...@@ -238,20 +255,14 @@ bool CvCaptureCAM_XIMEA::setProperty( int property_id, double value )
switch(property_id) switch(property_id)
{ {
// OCV parameters // OCV parameters
case CV_CAP_PROP_FRAME_WIDTH : mvret = xiSetParamInt( hmv, XI_PRM_WIDTH, ival); case CV_CAP_PROP_FRAME_WIDTH : mvret = xiSetParamInt( hmv, XI_PRM_WIDTH, ival); break;
if(mvret == XI_OK) width = ival; case CV_CAP_PROP_FRAME_HEIGHT : mvret = xiSetParamInt( hmv, XI_PRM_HEIGHT, ival); break;
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_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_GAIN : mvret = xiSetParamFloat( hmv, XI_PRM_GAIN, fval); break;
case CV_CAP_PROP_EXPOSURE : mvret = xiSetParamInt( hmv, XI_PRM_EXPOSURE, ival); break; case CV_CAP_PROP_EXPOSURE : mvret = xiSetParamInt( hmv, XI_PRM_EXPOSURE, ival); break;
// XIMEA camera properties // XIMEA camera properties
case CV_CAP_PROP_XI_DOWNSAMPLING : mvret = xiSetParamInt( hmv, XI_PRM_DOWNSAMPLING, ival); break; 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); case CV_CAP_PROP_XI_DATA_FORMAT : mvret = xiSetParamInt( hmv, XI_PRM_IMAGE_DATA_FORMAT, ival); break;
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_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_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; case CV_CAP_PROP_XI_TRG_SOURCE : mvret = xiSetParamInt( hmv, XI_PRM_TRG_SOURCE, ival); break;
...@@ -288,7 +299,7 @@ bool CvCaptureCAM_XIMEA::setProperty( int property_id, double value ) ...@@ -288,7 +299,7 @@ bool CvCaptureCAM_XIMEA::setProperty( int property_id, double value )
void CvCaptureCAM_XIMEA::errMsg(const char* msg, int errNum) void CvCaptureCAM_XIMEA::errMsg(const char* msg, int errNum)
{ {
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
char buf[512]; char buf[512]="";
sprintf( buf, "%s : %d\n", msg, errNum); sprintf( buf, "%s : %d\n", msg, errNum);
OutputDebugString(buf); OutputDebugString(buf);
#else #else
...@@ -297,3 +308,21 @@ void CvCaptureCAM_XIMEA::errMsg(const char* msg, int errNum) ...@@ -297,3 +308,21 @@ void CvCaptureCAM_XIMEA::errMsg(const char* msg, int errNum)
} }
/**********************************************************************************/ /**********************************************************************************/
int CvCaptureCAM_XIMEA::getBpp()
{
switch( image.frm)
{
case XI_MONO8 :
case XI_RAW8 : return 1;
case XI_MONO16 :
case XI_RAW16 : return 2;
case XI_RGB24 :
case XI_RGB_PLANAR : return 3;
case XI_RGB32 : return 4;
default :
return 0;
}
}
/**********************************************************************************/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment