Skip to content

Commit 01acb08

Browse files
committed
videoio: ximea - allow opening capture by serial number
1 parent 1d4a29f commit 01acb08

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

modules/videoio/src/cap.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,11 @@ CV_IMPL CvCapture * cvCreateFileCaptureWithPreference (const char * filename, in
354354
TRY_OPEN(result, cvCreateFileCapture_OpenNI2 (filename))
355355
if (apiPreference) break;
356356
#endif
357-
357+
#ifdef HAVE_XIMEA
358+
case CAP_XIAPI:
359+
TRY_OPEN(result, cvCreateCameraCapture_XIMEA(filename))
360+
if (apiPreference) break;
361+
#endif
358362
case CAP_IMAGES:
359363
TRY_OPEN(result, cvCreateFileCapture_Images (filename))
360364
}

modules/videoio/src/cap_ximea.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CvCaptureCAM_XIMEA : public CvCapture
1818
virtual ~CvCaptureCAM_XIMEA() { close(); }
1919

2020
virtual bool open( int index );
21+
bool open( const char* deviceName );
2122
virtual void close();
2223
virtual double getProperty(int) const;
2324
virtual bool setProperty(int, double);
@@ -26,6 +27,7 @@ class CvCaptureCAM_XIMEA : public CvCapture
2627
virtual int getCaptureDomain() { return CV_CAP_XIAPI; } // Return the type of the capture object: CV_CAP_VFW, etc...
2728

2829
private:
30+
bool _open();
2931
void init();
3032
void errMsg(const char* msg, int errNum) const;
3133
void resetCvImage();
@@ -51,6 +53,17 @@ CvCapture* cvCreateCameraCapture_XIMEA( int index )
5153
return 0;
5254
}
5355

56+
CvCapture* cvCreateCameraCapture_XIMEA( const char* serialNumber )
57+
{
58+
CvCaptureCAM_XIMEA* capture = new CvCaptureCAM_XIMEA;
59+
60+
if( capture->open( serialNumber ))
61+
return capture;
62+
63+
delete capture;
64+
return 0;
65+
}
66+
5467
/**********************************************************************************/
5568
// Enumerate connected devices
5669
void CvCaptureCAM_XIMEA::init()
@@ -75,13 +88,10 @@ void CvCaptureCAM_XIMEA::init()
7588
// Initialize camera input
7689
bool CvCaptureCAM_XIMEA::open( int wIndex )
7790
{
78-
#define HandleXiResult(res) if (res!=XI_OK) goto error;
79-
80-
int mvret = XI_OK;
81-
8291
if(numDevices == 0)
8392
return false;
8493

94+
int mvret = XI_OK;
8595
if((mvret = xiOpenDevice( wIndex, &hmv)) != XI_OK)
8696
{
8797
#if defined _WIN32
@@ -97,12 +107,33 @@ bool CvCaptureCAM_XIMEA::open( int wIndex )
97107
#endif
98108
}
99109

110+
return _open();
111+
}
112+
113+
bool CvCaptureCAM_XIMEA::open( const char* serialNumber )
114+
{
115+
if(numDevices == 0)
116+
return false;
117+
118+
int mvret = XI_OK;
119+
if((mvret = xiOpenDeviceBy(XI_OPEN_BY_SN, serialNumber, &hmv)) != XI_OK)
120+
{
121+
errMsg("Open XI_DEVICE failed", mvret);
122+
return false;
123+
}
124+
125+
return _open();
126+
}
127+
128+
bool CvCaptureCAM_XIMEA::_open()
129+
{
130+
#define HandleXiResult(res) if (res!=XI_OK) goto error;
100131
int width = 0;
101132
int height = 0;
102133
int isColor = 0;
103134

104135
// always use auto exposure/gain
105-
mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1);
136+
int mvret = xiSetParamInt( hmv, XI_PRM_AEAG, 1);
106137
HandleXiResult(mvret);
107138

108139
mvret = xiGetParamInt( hmv, XI_PRM_WIDTH, &width);

modules/videoio/src/precomp.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ CvCapture* cvCreateFileCapture_OpenNI( const char* filename );
126126
CvCapture* cvCreateFileCapture_OpenNI2( const char* filename );
127127
CvCapture* cvCreateCameraCapture_Android( int index );
128128
CvCapture* cvCreateCameraCapture_XIMEA( int index );
129+
CvCapture* cvCreateCameraCapture_XIMEA( const char* serialNumber );
129130
CvCapture* cvCreateCameraCapture_AVFoundation(int index);
130131
CvCapture* cvCreateCameraCapture_Aravis( int index );
131132

0 commit comments

Comments
 (0)