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.

9

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 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy