Ask Your Question
0

Read YUV image from filedump

asked 2017-01-05 09:16:43 -0600

subha gravatar image

updated 2017-01-05 09:35:36 -0600

berak gravatar image

Hello Guys, I am having yuv pixel contents(YUV420) as file dump. For example,

byte[1], byte[2]........byte[(width * height * 3)/2] in file.

I am having few questions:

1) How to read YUV pixels using file pointer and store in Mat object.

2) How to convert YUV Mat object to RGB Mat object.

I am using CPP code.

Thanks in Advance ...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-06 08:09:43 -0600

berak gravatar image

disclaimer: i've never done this ! but here is, what i'd try:

// 1. load it into an *1d* , uchar mat (else the 3/2 factor will get in your way):
Mat yuv(1, width * height * 3/2, CV_8U, bytepointer);

// 2. convert it to bgr. unfortunately, it has like 100 choices here, 
//     no idea, what to choose (you have to try)
Mat bgr;
cvtConvert(yuv, bgr, COLOR_YUV420sp2BGR);

// 3. reshape it to original size
bgr = bgr.reshape(-1, height);

for the list of possible conversions, see here

also, carefully looking at the docs of whatever gave you that buffer might be useful !

good luck !

edit flag offensive delete link more

Comments

Thanks...I used the above solution idea in my cpp code. It worked....

subha gravatar imagesubha ( 2017-01-19 02:51:48 -0600 )edit

@subha, do you remember the conversion flag , you used ? that would be useful information here.

berak gravatar imageberak ( 2017-01-19 02:55:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-05 09:10:22 -0600

Seen: 3,850 times

Last updated: Jan 06 '17