I want to convert a webcam shot in OpenCV to PIL so I can read the image pixel for pixel and get the RGB format.
I usually get the RGBA format when working with PIL, but now I get one integer instead of the four numbers I was expecting.
Consider this code snippet:
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, my_height)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, my_width)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FORMAT, cv.IPL_DEPTH_32F)
img = cv.QueryFrame(capture)
...
index_value = index_value + 1
picture_time = current_time + variance
#Give the cv image to PIL
im = Image.fromstring("L", cv.GetSize(img), img.tostring())
#Get the color set out of the images
width, height = im.size
image_pixels = im.load()
total_size = width * height
colors = {}
for h in range(height):
for w in range(width):
print width, height
detail = image_pixels[w, h]
#Filter our transparencies and dark colors
print detail
I get a value of things like 14 when I cover the webcam and 140 when I don't.
How do I properly grab an image from the webcam in a Pythonic way and get the RGB value of each pixel?