Ask Your Question
0

Fixing the color format of the video feed

asked 2017-08-23 14:50:30 -0500

skr_robo gravatar image

updated 2017-08-24 13:54:43 -0500

I am using the following code to access video feed from a camera (lsusb command in Jetson TX1 terminal lists the camera as Pixart Imaging, Inc.).

Code:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main()
{
        cv::VideoCapture cap(1);
        if(!cap.isOpened())
        {       
                std::cout << "Input error\n";
                return -1;
        }

        cv::namedWindow("Video Feed", cv::WINDOW_AUTOSIZE);

        for(;;)
        {
                cv::Mat frame;
                cap >> frame;
                std::cout << "Type: " << frame.type() << "\n";
                //cv::cvtColor(frame, frame, CV_YUV2RGB);
                //cv::resize(frame, frame, cv::Size2i(256, 144));
                cv::imshow("Video Feed", frame);        
                if (cv::waitKey(10) == 27)
                {
                        break;
                }
        }       
        cv::destroyAllWindows();
        return 0;
}

The screeenshots of the video feed can be seen below: image description

image description

I am trying to identify the color format of the camera and convert it to RGB. I have tried different color formats, but I focused mainly on YUV to RGB conversion as shown below (this line is commented out in the above code): cv::cvtColor(frame, frame, CV_YUV2RGB);

I have also tried different variants of YUV as listed here. However, I haven't received any result close to a normal RGB image.

I am also getting the following message on the terminal:

Corrupt JPEG data: 1 extraneous bytes before marker 0xd9

1) Is this just a defective camera?

2) Are there any tests/ approaches to identify and rectify the problem?

Edit based on comments:

I have tried YUV2BGR as well, but the results are same. Is there a way to figure out output format of the camera if the model is unknown?

edit retag flag offensive close merge delete

Comments

Using camera driver is a better approach to take control of parameters (white balance , color format ... etc).

Ziri gravatar imageZiri ( 2017-08-23 19:13:40 -0500 )edit
2

just saying, opencv uses BGR, not RGB order

berak gravatar imageberak ( 2017-08-24 00:38:41 -0500 )edit

I tried YUV2BGR as well. No change in the results.

skr_robo gravatar imageskr_robo ( 2017-08-24 13:50:39 -0500 )edit
1

Before converting what is the format returned by : cap.get(CV_CAP_PROP_FORMAT) ?

Ziri gravatar imageZiri ( 2017-08-25 02:22:59 -0500 )edit

Also, use VideoCapture::set() function to change your camera settings.

Ziri gravatar imageZiri ( 2017-08-25 02:35:08 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-08-25 05:17:56 -0500

Ziri gravatar image

Check your camera documentation if output is YUV or YUV422.

If source output is YUV422 it is supported by Opencv : (COLOR_YUV2RGB_UYVY or COLOR_YUV2RGB_Y422 )

(Also, Check your image depth if it's CV_8UC2 or CV_8UC3. )

If source is a non supported format you'll have to implement code for conversion.

edit flag offensive delete link more

Comments

I don't have documentation for this camera and the model is unknown, which is the stem of all problems. I printed format using std::cout << cap.get(CV_CAP_PROP_FORMAT);. It returned 16. I am trying to figure out what that means.

skr_robo gravatar imageskr_robo ( 2017-08-25 08:18:39 -0500 )edit

I tried the same code on my laptop and the webcam. The output of std::cout << cap.get(CV_CAP_PROP_FORMAT); was same: 16. But the images were fine.

skr_robo gravatar imageskr_robo ( 2017-08-25 10:33:22 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-08-23 14:50:30 -0500

Seen: 1,025 times

Last updated: Aug 25 '17