# Revision history [back]

### Fixing the color format of the video feed

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:

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.

1) Is this just a defective camera?

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

### Fixing the color format of the video feed

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:

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?

### Fixing the color format of the video feed

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:

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?

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?

### Fixing the color format of the video feed

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:

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?

I have tried YUV2BGR 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?