我在尝试运行python代码时遇到了一个问题
问题就在这里
File "touch_detect.py", line 24, in <module>
touch_detect()
File "touch_detect.py", line 19, in touch_detect
is_touching, certainty = touch_detect(source.image)
TypeError: touch_detect() takes 0 positional arguments but 1 was given下面是我的代码
import pytouch
from pytouch.handlers import ImageHandler
from pytouch.sensors import DigitSensor
from pytouch.tasks import TouchDetect
from pytouch import PyTouchZoo, sensors
def touch_detect():
source = ImageHandler("/home/../Documents/Digit2.png")
# initialize with task defaults
pt = pytouch.PyTouch(DigitSensor, tasks=[TouchDetect])
is_touching, certainty = pt.TouchDetect(source.image)
# initialize with custom configuration of TouchDetect task
touch_detect=TouchDetect(DigitSensor,zoo_model="touchdetect_resnet18")
is_touching, certainty = touch_detect(source.image)
print(f"Is touching? {is_touching}, {certainty}")
if __name__ == "__main__":
touch_detect()这段代码实际上是用于触觉感知的,并不是我写的代码,它被作为示例包含在一个名为pytouch的开源库中,该库用于几个应用程序,如我正在使用的触摸检测
发布于 2021-07-20 20:52:52
问题出在以下部分:
# initialize with custom configuration of TouchDetect task
touch_detect=TouchDetect(DigitSensor,zoo_model="touchdetect_resnet18")
is_touching, certainty = touch_detect(source.image)您使用一个参数(source.image)递归地调用touch_detect,但该函数不接受任何参数。
我假设您想在TouchDetect对象上调用一个方法,但是包含该对象的变量的名称与该方法的名称相同。我建议使用不同的变量名,或者更改方法的名称
https://stackoverflow.com/questions/68455083
复制相似问题