QLabel 显示opencv Mat

QLabel 显示opencv Mat

 

import cv2
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QLabel

label = QLabel()

# Load the image using OpenCV
image = cv2.imread("path/to/image.png")

# Convert the image to a QImage
height, width, channel = image.shape
bytesPerLine = 3 * width
qImg = QImage(image.data, width, height, bytesPerLine, QImage.Format_RGB888)

# Convert the QImage to a QPixmap and set it as the pixmap for the QLabel
pixmap = QPixmap.fromImage(qImg)
label.setPixmap(pixmap)

 

 

#########################

posted @ 2023-04-03 13:02  西北逍遥  阅读(90)  评论(0编辑  收藏  举报