Ask Your Question
0

cvtColor(): Bayer conversion scrambled pixels (channels?)

asked 2013-03-13 21:34:27 -0600

piedar gravatar image

updated 2013-03-13 23:54:16 -0600

I am new to OpenCV. I am trying to convert a cv::Mat of Bayer data to BGR. The input data is a 640*480 array of uint8_t. My code looks like this:

cv::Mat video_image;
cv::Mat raw(640, 480, CV_8UC1, frame->buffer.data());
cv::cvtColor(raw, video_image, CV_BayerGB2BGR);
cv::imshow("video", video_image)

BONUS QUESTION: Does the Mat constructor make a deep copy of the input data?

But video_image looks like this:

image description

I have tried CV_8UC3 and setting raw.step to 640*3. What am I missing?

PS: I took a screenshot because the highgui save image button had no apparent effect on the filesystem.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-03-14 05:41:12 -0600

berak gravatar image

updated 2013-03-14 05:49:00 -0600

  1. cv::Mat raw(640, 480, CV_8UC1, frame->buffer.data()); i'm unshure about bayer images, but CV_8UC1 would mean, that your input image has 1 channel only(gray). try CV_8UC3 (3 uchar channels) i think, you truncated it
  2. it's rows, cols there, not width height. (yes, happy here to confuse it evey 2nd time, too)
    so : cv::Mat raw(480,640, CV_8UC3, frame->buffer.data());
  3. BONUS: NO, that constructor only copies the pointer and sets up rows/cols and such, no deep copy, so careful with that!!. but you're safe here, since the following cvtColor() WILL alloc new space for the result image. in other situations, when you're using such a constructor with a 'borrowed' pointer you'd want to clone() it
edit flag offensive delete link more

Comments

Thanks! I spend hours on this last night. I can't believe it was just rows, cols instead of width, height. CV_8UC1 was right in this case.

piedar gravatar imagepiedar ( 2013-03-14 11:52:08 -0600 )edit

Question Tools

Stats

Asked: 2013-03-13 21:34:27 -0600

Seen: 6,308 times

Last updated: Mar 14 '13