tags:

views:

127

answers:

3

I've seen from the sample how to display an image from the webcam, but how do I get the image captured as an array?

import cv

capture = cv.CaptureFromCAM(0)
img = cv.QueryFrame(capture)

img.tostring() gives me weird caracters. Thanks in adv.

A: 

According to the docs, QueryFrame returns an IplImage. IplImage can be treated as an arbitrary array. It looks like you'll want to use the "Get" set of functions to access array elements.

Mark
Thanks, I didn't knew how to manipulate it. I had found a way to convert it to a PIL image and then accesses as an array.img_array = Image.fromstring("RGBA",cv.GetSize(img), img.tostring() )
PuercoPop
+1  A: 

I believe your problem might be the way you are printing/displaying the contents of the array.

Nevertheless, this blog post shows how to capture frames from a webcam on linux using python.

karlphillip
+1  A: 

I think this is what you're looking for:

img=cv.LoadImage("asd.png")
mat=cv.GetMat(img)
mat[3,1]
(83.0, 88.0, 89.0)

anyway, you should check opencv python cookbook for use with PIL and NUMPY packages.

dnul