def numpy_array_to_qpixmap(self, numpy_array):
numpy_array = cv2.cvtColor(numpy_array, cv2.COLOR_BGR2RGB) # 转换颜色通道为 RGB
height, width, channel = numpy_array.shape
bytesPerLine = 3 * width
qimage = QImage(numpy_array.data, width, height, bytesPerLine, QImage.Format_RGB888)
pixmap = QPixmap.fromImage(qimage)
return pixmap
def run(self):
print(self.input_img_path)
results = self.model([self.input_img_path],
save=False,
conf=float(self.conf),
iou=float(self.iou),
imgsz=640,
device="cpu") # use cuda:0
# results[0].save(filename='result2.jpg') # save to disk
img = results[0].plot()
print(type(img))
print("图像检测完毕")
pixmap = self.numpy_array_to_qpixmap(img)
【pyqt】yolo检测图转换为Qpixmap
于 2024-03-30 12:35:59 首次发布