Accessing Y information from Raspicam (Python)

asked 2015-08-04 05:40:14 -0500

updated 2015-08-04 06:27:39 -0500

thdrksdfthmn gravatar image

Hi, I am having trouble loading a YUV array in OpenCV. I am trying it on a raspberry pi and I used the code that I saw in the answer to this question

Essentially, I have gotten raw YUV info from the Raspberry pi camera and I have it converted to a numpy array, frame by frame. My question now is: how can i see this numpy array in OpenCV? I would like to load the frames as images, and ultimately, I would like to isolate the Y channel for analysis. SO far, I just got the array and did this:

img = cv2.imread('ArrayY',0)

Which is probably wrong. Thanks for your help in advance,



edit retag flag offensive close merge delete


"Why do you think is this wrong?" is my question

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-04 06:29:39 -0500 )edit

Hi, Sorry, I know this is wrong because I get an error :

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/pi/OpenCV/opencv-2.4.11/modules/highgui/src/window.cpp, line 261 Traceback (most recent call last): File "", line 26, in <module> cv2.imshow('image',img) cv2.error: /home/pi/OpenCV/opencv-2.4.11/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

I do not know if these means that OPenCV cannot read the numpy data or if it simply means that it can read it, but it cannot open it as an image for some reason?

kingdavidek gravatar imagekingdavidek ( 2015-08-04 06:37:44 -0500 )edit

This is because you have nothing loaded in img. if you do if(img.empty()) print "no image loaded" what do you get? (sorry ig my python is bad :) )

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-04 07:29:46 -0500 )edit

I just tried it. And you are correct, i got the error I wrote

img = cv2.imread('array',0) if (img): cv2.imshow('image',img) else: print "no image loaded"

And I got 'no image loaded'. What am I doing wrong?

kingdavidek gravatar imagekingdavidek ( 2015-08-04 08:48:44 -0500 )edit

Have you used the entire path of the image?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-04 09:43:20 -0500 )edit

I don't know. But the images I am trying to read are simply the frames of the video capture, so they should only be accessible within the program right?

Also, if it helps, I did array.shape on the array and it returned (256, 256, 3). Are these the dimensions of the matrix? Ie. is it a 256 by 256 by 3 matrix?

kingdavidek gravatar imagekingdavidek ( 2015-08-04 10:00:01 -0500 )edit

If you use the videoCapture, then use its read() function

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-04 10:18:04 -0500 )edit

I want to avoid using videocapture because I would like to access the frames straight from the GPU. If i have a numpy array, which i do, shouldn't i theoretically be able to access it in opencv?

kingdavidek gravatar imagekingdavidek ( 2015-08-04 10:34:03 -0500 )edit

then you should be able to do decode, maybe, or just fill the mat with the buffer (sadly I do not know python, to help you how...)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-04 10:43:59 -0500 )edit

what would i be decoding? The final array? Would I do this simply with the imdecode function?

kingdavidek gravatar imagekingdavidek ( 2015-08-04 10:54:16 -0500 )edit