I want to read and show a video using opencv. I've recorded with Direct-show, the Video has UYVY (4:2:2) codec, since opencv can't read that format, I want to convert the codec to an RGB color model, I readed about ffmpeg and I want to know if it's possible to get this done with it ? if not if you a suggestion I'll be thankful.
Asked
Active
Viewed 1,666 times
0
-
`UYVY` is one of the [popular] pixel formats. You can definitely read from this file using DirectShow API, all the standard methods. Conversion into RGB is built into Windows. It is hard to tell why you cannot use the file you created. – Roman R. Feb 13 '13 at 19:28
-
I know to read but I don't know how to convert it ` – Engine Feb 13 '13 at 19:32
-
I never heard of **RBB**, what is it? – karlphillip Feb 13 '13 at 20:52
1 Answers
1
As I explained to you before, OpenCV can read some formats of YUV, including UYVY (thanks to FFmpeg/GStreamer). So I believe the cv::Mat
you get from the camera is already converted to the BGR color space which is what OpenCV uses by default.
I modified my previous program to store the first frame of the video as PNG:
cv::Mat frame;
if (!cap.read(frame))
{
return -1;
}
cv::imwrite("mat.png", frame);
for(;;)
{
// ...
And the image is perfect. Executing the command file
on mat.png reveals:
mat.png: PNG image data, 1920 x 1080, 8-bit/color RGB, non-interlaced
A more accurate test would be to dump the entire frame.data()
to the disk and open it with an image editor. If you do that keep in mind that the R and B channels will be switched.

Community
- 1
- 1

karlphillip
- 92,053
- 36
- 243
- 426