【发布时间】:2014-04-29 01:26:16
【问题描述】:
我正在尝试为轮廓创建一个跟踪栏,但是当我运行代码时出现此错误:
TypeError: thresh_callback() takes exactly 3 arguments (1 given)
代码:
def thresh_callback(thresh,blur,img):
edges = cv.Canny(blur,thresh,thresh*2)
drawing = np.zeros(img.shape,np.uint8) # Image to draw the contours
contours,hierarchy = cv.findContours(edges,cv.RETR_TREE,cv.CHAIN_APPROX_SIMPLE)
for cnt in contours:
color = np.random.randint(0,255,(3)).tolist() # Select a random color
cv.drawContours(drawing,[cnt],0,color,2)
cv.imshow('output',drawing)
cv.imshow('input',img)
def Pics():
vc = cv.VideoCapture(2)
retVal, frame = vc.read();
while True :
if frame is not None:
imgray = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
blur = cv.GaussianBlur(imgray,(5,5),0)
thresh = 100
max_thresh = 255
cv.createTrackbar('canny thresh:','input',thresh,max_thresh,thresh_callback)
thresh_callback(thresh,blur,frame)
rval, frame = vc.read()
if cv.waitKey() & 0xFF == 27:
break
cv1.DestroyAllWindows()
【问题讨论】:
-
请修正你的缩进。
-
我看到的例子只传递了一个低阈值到回调,所以只有 一个 参数。
-
我认为
cv(遗留模块,而不是 cv2...)不会返回帧、图像等 - 它的行为更像是一个 c 函数,因为您传入输出.这意味着blur(可能还有frame)可能是空的? -
@jmetz: IT 是
createTrackbar函数,它被传递了回调,它反过来用一个参数调用回调。 -
@jmetz:这就是为什么完整的回溯在这里会有所帮助。