需要在capture()
类中调用Camera
方法(省略)。只需在脚本中运行代码即可运行它:
# import io, picamera, etc..
with picamera.PiCamera() as camera:
camera.resolution(self.camwidth, self.camheight)
camera.start_preview()
当我尝试使其面向对象时失败:
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)
错误如下所示:
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
我尝试了不同的方法,但行:
camera.resolution(self.camwidth, self.camheight)
..似乎是从对象内部出现问题的那个。始终“元组对象不可调用。我也尝试将__init__()
设置为仅注册32x24值和cameraSetup()
方法,以便在调用camera.cameraSetup()
答案 0 :(得分:1)
camera.resolution是一个元组。这意味着它的数组数据结构在实例化之后无法修改。你绝对不能把它称为功能。相反,将它指向一个新的元组。
camera.resolution = (self.camwidth, self.camheight)