Ask Your Question
0

Creating a Mat object from a YV12 image buffer

asked 2013-09-11 03:05:12 -0600

s4eed gravatar image

updated 2013-09-11 05:11:39 -0600

Hi ! I have a buffer which contains an image in YV12 format. Now I want to either convert this buffer to rbg or create a Mat object from it directly! Can someone help me? I tried moster's way :

cv::Mat input(rows, cols, CV_8UC1, buffer);
cv::Mat converted;
cv::cvtColor(input, converted, CV_YUV2RGB_YV12);

Now images look like this : image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-09-11 04:04:15 -0600

Moster gravatar image

updated 2013-09-11 04:05:27 -0600

You could try to create a Mat with cv::Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP) and cvtColor to convert it then.

cv::Mat input(rows, cols, CV_8UC1, buffer);
cv::Mat converted;
cv::cvtColor(input, converted, CV_YUV2RGB_YV12);

Im not completely sure if assuming that the buffer is an 8bit unsigned char image will work, but you could give it a try.

edit flag offensive delete link more

Comments

thank you. I used your way I updated my question. I got a picture but it wasn't the right one yet.

s4eed gravatar images4eed ( 2013-09-11 05:13:30 -0600 )edit

Do you use cv::imshow() ?

Moster gravatar imageMoster ( 2013-09-11 05:18:58 -0600 )edit

No I saved it.

s4eed gravatar images4eed ( 2013-09-11 05:28:35 -0600 )edit

Try cv::cvtColor(input, converted, CV_YUV2BGR_YV12);

As far as I know opencv always needs BGR for imwrite or imshow.

Moster gravatar imageMoster ( 2013-09-11 05:34:53 -0600 )edit

Nothing changed ! :-| :-(

s4eed gravatar images4eed ( 2013-09-11 05:37:40 -0600 )edit

Ok, then do trial & error :P As I said, Im not completely sure which cv_type YV12 needs. So try: CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC2, CV_16UC3, CV_16UC4.

Stay with BGR :cvtColor(input, converted, CV_YUV2BGR_YV12)

Moster gravatar imageMoster ( 2013-09-11 05:48:59 -0600 )edit

OK.Thank you!

s4eed gravatar images4eed ( 2013-09-11 05:53:21 -0600 )edit

Question Tools

Stats

Asked: 2013-09-11 03:05:12 -0600

Seen: 2,877 times

Last updated: Sep 11 '13