read camera image incorrect
I using the function of videocapture to read camera data
VideoCapture cap(0);
int Key;
Mat src;
if(cap.isOpened())
{
while(1)
{
cap.read(src);
namedWindow("capture", 0);
imshow("capture",src);
Key = waitKey(10);
if(Key ==27)
break;
}}
The output is likely bayer image with green vision And the image size is not correct(640X480), it should be 2592X1944 in raw 12 bits.
Is some parameters for function videocapture need I set? or have anything I miss for opencv videocapture?
----------------------------------------------------------------------------------------------------------------
I got it!
The problem is causing by a function which is translating raw data to bayer pattern.
The camera input is raw in 12 bits format, as reading the camera data that one element is separated to two bytes (low byte and high byte)
We need to merge this two byte to a int format(0~2^8 -> 0~2^16).
OpenCV has a mistake in the data merging, so I got the wrong image first.
I coding that translating raw data to bayer pattern and getting the correct result without white balance.
Hi, I'm having the same problem. I've used cvtColor but, my image is still not displaying correctly. I've pasted my code below and have included a link to the resulting image. Can you see what I'm doing wrong? cv::VideoCapture (cam1);
cam1.grab();
cam1.read(data);
....
cv::Mat changed;
cv::Mat bayer16(data.rows, data.cols, CV_16UC1,data.data,data.step);
cv::Mat bayer8 = bayer16.clone();
bayer8.convertTo(bayer8, CV_8UC3, 0.0625);
cv::cvtColor(bayer8, changed, CV_BayerGB2BGR);
imshow("", changed);
Resulting image
I have an PointGrey BlackFly that reads as three 8-bit channels in Python's Numpy array of shape (rows, cols, 3). However, each cell (pixel) has the same value, so I end up with a gray-scale image-like by default. I tried several conversions of color, but Bayer cannot go from 3 channels to anything else. Does anyone know which property to set for this VideoCapture object or any other suggestion? I'm not sure which Video Data Output it's using, perhaps it's 24-bit digital data it's giving 24-bits per pixel as (8,8,8), but maybe not. How to find out the video format within OpenCV? If I ask for get(CAP_PVAPI_PIXELFORMAT_RGB24) it give 15.0, get(CAP_PVAPI_PIXELFORMAT_BAYER16) gives 480.0, and get(CAP_PVAPI_PIXELFORMAT_BAYER8) gives 640.0. Any other PIXELFORMAT gives -1. I don't understand it.
@elfsingle Can you share your final code that works, because I did not understand your explanation. I am a newbie and I rhave the same problem.