以下代码给出了错误:"" TypeError:src不是一个numpy数组,也不是标量""通过使用cv2。图像被定义为带有photoimage的灰度图像。图像显示正确,我不明白它为什么不起作用。
#Photoimage
self.imgTk=ImageTk.PhotoImage(img)
#label the image
label = Tk.Label(self.canvasright,image=self.imgTk)
label.image = self.imgTk # keep a reference!
label.pack()
#img.save('img_gif','gif')
#imgTk=ImageTk.PhotoImage(img)#('img_gif')
#PhotoImage(master = self.canvasright, width = WIDTH, height = HEIGHT)
#self.canvasright.image=self.imgTk
#self.canvasright.create_image(0,0,image=label,anchor=Tk.NW)
#self.canvasright.pack()
def find_balls(self):
imggray=cv2.cvtColor(self.imgTk, cv2.COLOR_BGR2GRAY)
self.circles = cv2.HoughCircles(imggray,cv.CV_HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=0,maxRadius=200)
print self.circles
答案 0 :(得分:0)
对于opencv你需要将图像作为numpy数组传递
在你的函数def find_balls(self)中:执行以下操作
在函数
中立即添加一行def find_balls(self):
#Add this Line
temp_image = cv2.imread(self.imgTk)
#This will read the image and convert it to a numpy array
#Now replace the first parameter(self.imgTk to temp_image) in the next line
imggray=cv2.cvtColor(temp_image, cv2.COLOR_BGR2GRAY)
self.circles = cv2.HoughCircles(imggray,cv.CV_HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=0,maxRadius=200)
print self.circles