Domanda

Need to call a capture() method (omitted) in the Camera class. Just running the code in a script runs it OK:

# import io, picamera, etc..
with picamera.PiCamera() as camera:
    camera.resolution(self.camwidth, self.camheight)
    camera.start_preview()

When I try to make it object oriented it fails:

class Camera(object):
    def __init__(self, cam_width, cam_height):
        self.camwidth = cam_width
        self.camheight = cam_height
        with picamera.PiCamera() as camera:
            camera.resolution(self.camwidth, self.camheight)
            camera.start_preview()
            time.sleep(2)

camera = Camera(32, 24)

The error looks like this:

File "ActionScript.py", line 23, in <module> camera = Camera(32, 24)
File "ActionScript.py", line 13, in __init__ camera.resolution(self.camwidth,self.camheight)
TypeError: 'tuple' object is not callable

I have tried different ways around this, but the line:

camera.resolution(self.camwidth, self.camheight)

.. seems to the one it has a problem with from inside an object. Always "tuple object is not callable. I have also tried setting __init__() to just registering the 32x24 values and a cameraSetup() method to run the setup with the same result after calling camera.cameraSetup()

È stato utile?

Soluzione

camera.resolution is a tuple. This means its a array data structure which cannot be modified past its instantiation. You definitely can't call it like a function either. Instead, point it to a new tuple.

camera.resolution = (self.camwidth, self.camheight)

source: http://picamera.readthedocs.org/en/latest/recipes1.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top