# Revision history [back]

### Placing UYVY data in a Mat, C++

Hi,

I have image data in UYVY form (according to fourcc), Like here: http://fourcc.org/pixel-format/yuv-uyvy

For instance: Image width: 100, image height 300. So the data has 200 columns (as it is stored in UYVY it is two times the image width ) and 300 rows of uint8_t values.

So far so simple.

All i want is to get that data in a Mat within C++

What i tried (and this is, i assume, naive)

Let´s say data is the pointer to the data i already have.

Mat frame = Mat(300, 100, CV_8UC2, data);
imshow("frame", frame);


But i am getting Memory faults.

Do i have to declare the Mat with ... (300,200, ...) as it is UYVY data. I guess not ! ? Also: CV_8UC2 should be correct for UYVY data, right ?

What i am doing wrong ?

Does the Mat somehow need to know, that it is UYVY data? Yes ! But how ? Declaring CV_8UC2 while creating the Mat object (like in the code above) does obviously only create the space, but the mat and so imshow do not know in which order (format) the image data is stored.

My data (and so the pointer) is correct, i checked that. Maybe the problem is, that Mat does store the data not as uint8_t, but as ... whatever --- larger than a byte. that would also be a reason, why i get memory faults.

My problem formulated in one sentence is: How can i get uint8_t data in UYVY order in a Mat?

Best regards

Markus

### Placing UYVY data in a Mat, C++

Hi,

I have image data in UYVY form (according to fourcc), Like here: http://fourcc.org/pixel-format/yuv-uyvy

For instance: Image width: 100, image height 300. So the data has 200 columns (as it is stored in UYVY it is two times the image width ) and 300 rows of uint8_t values.

So far so simple.

All i want is to get that data in a Mat within C++

What i tried (and this is, i assume, naive)

Let´s say data is the pointer to the data i already have.

Mat frame = Mat(300, 100, CV_8UC2, data);
imshow("frame", frame);


But i am getting Memory faults.

Do i have to declare the Mat with ... (300,200, (300,200, ...) as it is UYVY data. I guess not ! ? Also: CV_8UC2 should be correct for UYVY data, right ?

What i am doing wrong ?

Does the Mat somehow need to know, that it is UYVY data? Yes ! But how ? Declaring CV_8UC2 while creating the Mat object (like in the code above) does obviously only create the space, but the mat and so imshow do not know in which order (format) the image data is stored.

My data (and so the pointer) is correct, i checked that. Maybe the problem is, that Mat does store the data not as uint8_t, but as ... whatever --- larger than a byte. that would also be a reason, why i get memory faults.

My problem formulated in one sentence is: How can i get uint8_t data in UYVY order in a Mat?