Kivy camera get image

Viewed 783

I am trying to use kivy to capture an image of a QR. Using

from kivy.uix.camera import Camera
self.cameraObject = Camera(play=True,resolution=(640,480),index=0)

I successfully captured an image which I can save to a file

self.cameraObject.export_to_png('./selfie.png')

I wish to get the picture into a variable then used to check for QR codes. I could read the image in from the file I just saved but the image is already stored in the camera object. I am unable to find a Camera method that returns the image. What I would like to do is something like;

frame=self.cameraObject.get_image()

Sadly this doesn't seem to exist and I cannot see a likely command in the Camera methods list. Is this possible to do?

2 Answers

You can get a reference to the Texture of the Camera Image using:

texture = self.cameraObject.texture

Note that texture will change with each frame the Camera captures.

You can get the array of pixels from the Texture:

pixels = texture.pixels

Okay that worked....so

import numpy
from PIL import Image

texture = self.cameraObject.texture
size=texture.size
pixels = texture.pixels
pil_image=Image.frombytes(mode='RGBA', size=size,data=pixels)
numpypicture=numpy.array(pil_image)

Thank you Mr Anderson

Related