Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give YUV data input to Opencv?

Tags:

opencv

mat

yuv

I am a beginner to Opencv. In my new opencv project I have to capture video frames from a camera device and need to give them to the opencv for processing, But now my camera is not working(hardware issue). And I need to test the opencv application with a YUV file obtained from another camera device of the same type. So my questions are: How can i give YUV data to opencv? Does opencv support YUV data?

From my investigation I could know that The opencv converts the captured frames to a format Mat.So Is there any way to convert the YUV data directly to Mat object and given to the opencv for processing.

My device doesn't have any codecs for MPEG ,AVI etc

like image 986
Vineesh Vijayan Avatar asked Sep 29 '22 01:09

Vineesh Vijayan


1 Answers

I asked a similar question recently here OpenCV capture YUYV from camera without RGB conversion

An openCV VideoCapture object is the easiest way to capture video, but it automatically converts the frames to BGR format. You can disable this with videoCapture.set(CV_CAP_PROP_CONVERT_RGB, false)

For some reason that particular command didn't work with my camera so I was forced to use V4L2 library to read frames instead (this is the same library that videoCapture uses). Sample video capture code for V4L2: http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html. I then stored the frames in a cv::Mat for processing.

You can store data of any format in an openCV Mat, but some operations make assumptions about what format the data is in. For example imshow will assume the data is either BGR or greyscale format. If your data isn't one of those formats your image will look wrong.

like image 84
titch Avatar answered Nov 01 '22 11:11

titch