【问题标题】:Instance not callable 'tuple' object实例不可调用的“元组”对象
【发布时间】:2014-05-12 21:19:26
【问题描述】:

需要在Camera 类中调用capture() 方法(省略)。只需在脚本中运行代码即可运行它:

# 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() 后以相同的结果运行设置

【问题讨论】:

    标签: python camera raspberry-pi raspbian


    【解决方案1】:

    camera.resolution 是一个元组。这意味着它是一个数组数据结构,在其实例化之后无法修改。你也绝对不能像函数一样调用它。相反,将其指向一个新元组。

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

    来源:http://picamera.readthedocs.org/en/latest/recipes1.html

    【讨论】:

      猜你喜欢
      • 2020-08-29
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      • 2022-06-15
      相关资源
      最近更新 更多