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;
#if CV_MAJOR_VERSION == 2
capturedFrame = cvCreateImage(cvSize(img.width, img.height), IPL_DEPTH_8U,depth);
#elif CV_MAJOR_VERSION == 3
IplImage * image = cvCreateImage(cvSize(img.width, img.height),
IPL_DEPTH_8U, depth);
capturedFrame = cvarrToMat(image);
#endif
Mat capturedFrame;
memcpy(capturedFrame.data, img.bp, img.width * img.height*depth);