【发布时间】:2018-08-02 09:01:12
【问题描述】:
我创建了一个代码,当点击“加载”时,用户将上传一个 .png 图像,opencv 将执行 houghcircle 并计算圈数。
和计数,将显示在文本标签上。 circles.shape 会导致 (1, 99, 3),我想在 textlabel 上显示 99,甚至是整个 (1, 99, 3)。
问题是,上传图片后出现此错误
Traceback(最近一次调用最后一次): 文件“try.py”,第 58 行,在浏览中 self.label_2.setText(circles.shape) TypeError: setText(self, str): argument 1 has unexpected type 'tuple'
这是我的代码:
def Browse(self):
filter = "Images (*.png)"
fname, _ = QFileDialog.getOpenFileName(self, "Open Image", "Desktop", filter)
print(fname)
self.scene = QGraphicsScene()
self.scene.addPixmap(QPixmap(fname))
self.graphicsView_2.setScene(self.scene)
img = cv2.imread(fname,0)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,5,
param1=200,param2=8,minRadius=0,maxRadius=7)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),1)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),1)
numberofcells = print(circles.shape)
self.label_2.setText(circles.shape)
任何帮助将不胜感激。非常感谢!
【问题讨论】:
-
shape 返回一个元组(高度、宽度、通道),而不是 str。您不能使用元组作为参数调用 setText
标签: python python-3.x opencv pyqt pyqt5