26 lines
596 B
Python
26 lines
596 B
Python
import logging
|
|
|
|
import PySide6
|
|
import cv2
|
|
from PyQt5.QtGui import QImage, QPixmap
|
|
|
|
from Util.util_log import log
|
|
|
|
|
|
def cv2_to_qpixmap(cv_img):
|
|
"""将OpenCV图像转换为QPixmap"""
|
|
if cv_img.shape !=3:
|
|
print("cv_img.shape !=3")
|
|
return None
|
|
try:
|
|
img = cv_img.copy()
|
|
height, width, channel = img.shape
|
|
bytes_per_line = 3 * width
|
|
q_img = QImage(img.data, width, height, bytes_per_line, QImage.Format_RGB888)
|
|
return QPixmap.fromImage(q_img)
|
|
except Exception as e:
|
|
log.log_message(logging.ERROR, e)
|
|
return None
|
|
|
|
|