Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python3类参数错误_Python_Class_Python 3.5 - Fatal编程技术网

python3类参数错误

python3类参数错误,python,class,python-3.5,Python,Class,Python 3.5,我正在尝试用python 3.5创建一个类 这是类文件 import numpy as np import cv2 from threading import Thread class perstrans: def __init__(self,a,img,s): self.name=a self.imx = img.shape[1] self.imy = img.shape[0] self.src = np.float32

我正在尝试用python 3.5创建一个类 这是类文件

import numpy as np
import cv2
from threading import Thread

class perstrans:
    def __init__(self,a,img,s):
        self.name=a
        self.imx = img.shape[1]
        self.imy = img.shape[0]
        self.src = np.float32(
            [[28, 198], [252, 198], [203, 140], [79, 141]],
            [[28, 198], [252, 198], [203, 140], [79, 141]])
        self.dst = np.float32(
            [[0, imy],
             [imx, imy],
             [imx, 0],
             [0, 0]])
        self.pmat = cv2.getPerspectiveTransform(self.src[s[1]], self.dst)
        return None
    def transfer(self,image):
        Thread(target=self.perstr, args=(image)).start()

    def perstr(self,imaga):
        self.h, self.w = imaga.shape[:2]
        self.res = cv2.warpPerspective(imaga, m, (w,h), flags=cv2.INTER_LINEAR)
        return self

    def getres(self):
        return self.res
但是当我像这里一样初始化它时,我得到了以下错误

import cv2
import numpy as np
import perstrans
cap = WebcamVideoStream(0).start()
img = cap.read()   
img = cv2.resize(img,(resizex,resizey))
h, w = img.shape[:2]
trns=perstrans.perstrans("angle",img,0)
....


Traceback (most recent call last):
  File "main.py", line 39, in <module>
    trns=perstrans.perstrans("angle",img,0)
  File "/home/huzeyfe/Desktop/robotaksi data/line tracking/duzenlenmis/v2/perstrans.py", line 12, in __init__
    [[28, 198], [252, 198], [203, 140], [79, 141]])
TypeError: function takes at most 1 argument (2 given)
导入cv2
将numpy作为np导入
进口有机玻璃
cap=WebcamVideoStream(0).start()
img=上限读取()
img=cv2.调整大小(img,(resizex,resizey))
h、 w=图像形状[:2]
trns=过变速器。过变速器(“角度”,img,0)
....
回溯(最近一次呼叫最后一次):
文件“main.py”,第39行,在
trns=过变速器。过变速器(“角度”,img,0)
文件“/home/huzeyfe/Desktop/robotaksi data/line tracking/duzenlenmis/v2/pertrans.py”,第12行,在__
[[28, 198], [252, 198], [203, 140], [79, 141]])
TypeError:函数最多接受1个参数(给定2个)
谢谢


注意:这个问题可能是重复的,但我看到的大多数问题都是函数decelleration中的自缺失问题,我找不到与我类似的问题

这不是类的问题。您只是试图将两个单独的参数传递给
np.float32()

仔细看。这是列表的两倍
[[28198],[252198],[203140],[79141]
np.float32()
只接受一个参数

更正该行以传入一个参数

并不是说你的代码在那之后还能工作;还有更多的问题:

  • s
    被视为可以在类中索引的内容
    \uuuu init\uuu
    方法:

    self.pmat = cv2.getPerspectiveTransform(self.src[s[1]], self.dst)
    #                                                ^^^^
    
    请注意
    s[1]
    ,但是您对该类的使用为
    s
    传递了一个整数值:

    trns=perstrans.perstrans("angle",img,0)
    #                                    ^
    
    因此,
    s[1]
    也将失败,出现
    TypeError:“int”对象不可下标

  • 您只是将图像作为
    Thread()
    args
    参数传入;括号不会使其成为元组:

    Thread(target=self.perstr, args=(image)).start()
    #                               ^^^^^^^
    
    您需要在此处添加逗号,否则会出现更多错误(具体取决于
    image
    引用的对象类型):

np.float32()
只是不包含两个单独的列表。
Thread(target=self.perstr, args=(image)).start()
#                               ^^^^^^^
Thread(target=self.perstr, args=(image,)).start()