我想用代码“ self.displayImage(2)”将裁剪后的图像(变量为“ roi_color”的图像)显示为Qt标签,并将“ self”更改为“ roi_color”,但我的应用程序停止了代替工作
def haarClicked(self):
gray = cv2.cvtColor(self.image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.25, 2)
for (x, y, w, h) in faces:
cv2.rectangle(self.image, (x, y), (x+w, y+h), (255, 0, 0), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_color = self.image[y:y + h, x:x + w]
#cv2.imshow("cropped", roi_color)
self.image = self.image[y:y + h, x:x + w]
self.displayImage(2)
def displayImage(self, windows=1):
qformat=QImage.Format_Indexed8
if len(self.image.shape)==3:
if(self.image.shape[2])==4:
qformat=QImage.Format_RGBA8888
else:
qformat=QImage.Format_RGB888
img=QImage(self.image,self.image.shape[1],self.image.shape[0],self.image.strides[0],qformat)
img=img.rgbSwapped()
if windows==1:
self.imgLabel.setPixmap(QPixmap.fromImage(img))
self.imgLabel.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)
self.imgLabel.setScaledContents(True)
if windows==2:
self.haarLabel.setPixmap(QPixmap.fromImage(img))
self.haarLabel.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)
self.haarLabel.setScaledContents(True)