Accessing Y information from Raspicam (Python)
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)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Which is probably wrong. Thanks for your help in advance,
Cheers,
David
"Why do you think is this wrong?" is my question
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 "captureYUV.py", 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?
This is because you have nothing loaded in
img
. if you doif(img.empty()) print "no image loaded"
what do you get? (sorry ig my python is bad :) )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?
Have you used the entire path of the image?
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?
If you use the videoCapture, then use its read() function vcap.read(img)
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?
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...)
what would i be decoding? The final array? Would I do this simply with the imdecode function?