Ximea MU9PC Color Camera And OpenCV to Capture a Frame

For capturing a frame from Ximea Color camera MU9PM with OpenCV, we need to do the followings:

Initializing camera parameters for capturing from Color Camera

these are some of the parameters related to capturing in Color. Other related parameters can be found at Ximea Documentation Page

  //at first need to open the device for capturing

int deviceIndex=0;
HANDLE cameraHandle;

  xiOpenDevice(deviceIndex, &cameraHandle);

// default image format RGB24
xiSetParamInt(cameraHandle, XI_PRM_IMAGE_DATA_FORMAT, XI_RGB24);

xiSetParamInt(cameraHandle, XI_PRM_AUTO_WB, 0);
xiSetParamFloat(cameraHandle, XI_PRM_GAMMAY, 1);
xiSetParamFloat(cameraHandle, XI_PRM_GAMMAC, 0);


And after that need starting the acquisition:

if (xiStartAcquisition(cameraHandle) != XI_OK) {
printf("xiStartAcquisition Error");
return false;


Capturing the frame

At first we allocate memory for the captured image and then getting the buffer from the camera and copying it in the allocated place.

XI_IMG img;
memset(&img, 0, sizeof(img));
img.size = sizeof(XI_IMG);
//depth of color images is 3
 depth = 3;
capturedFrame = cvCreateImage(cvSize(img.width, img.height), IPL_DEPTH_8U,depth);

IplImage * image = cvCreateImage(cvSize(img.width, img.height),
IPL_DEPTH_8U, depth);
capturedFrame = cvarrToMat(image);

Mat capturedFrame;
memcpy(, img.bp, img.width * img.height*depth);