How to Use Cv_Cap_Prop_Fourcc?
It Seems Simple but I Couldn't Get It to Work. I Want to Print out the Format of an Image by Using cvGetCaptureProperty(image, Cv_Cap_Prop_Fourcc) Where Image...
It seems simple but I couldn't get it to work. I want to print out the format of an image by using
cvGetCaptureProperty(image, CV_CAP_PROP_FOURCC)
where image is an object of CvCapture struct.
This function returns double. I did convert it to char* so that I can print out the format but it didn't work. Any suggestions?
2 Answers
Get a double* and convert that:
double f = cvGetCaptureProperty(image, CV_CAP_PROP_FOURCC);
char* fourcc = (char*) (&f); // reinterpret_cast
However, this OpenCV highgui tutorial suggests the following with the C++ interface:
int ex = static_cast<int>(inputVideo.get(CV_CAP_PROP_FOURCC));
// Transform from int to char via Bitwise operators
char EXT[] = {(char)(ex & 0XFF),(char)((ex & 0XFF00) >> 8),(char)((ex & 0XFF0000) >> 16),(char)((ex & 0XFF000000) >> 24),0};
Of course, instead of the get method, you'd use cvGetCaptureProperty.
You can use the following function:
//
void fourCCStringFromCode(int code, char fourCC[5]) {
for (int i = 0; i < 4; i++) {
fourCC[3 - i] = code >> (i * 8);
}
fourCC[4] = '\0';
}
For instance:
double f = cvGetCaptureProperty(capture, CV_CAP_PROP_FOURCC);
printf("fourcc=%d\n", f); // outputs fourcc=6
char fourcc[5];
fourCCStringFromCode((int)f, fourcc);
printf("fourcc=%s\n", fourcc); // outputs fourcc=DIVX