From 1efd0385e158c240dc24c7c9f0459f8dcc4aad7b Mon Sep 17 00:00:00 2001 From: FrankCV2048 <1395405735@qq.com> Date: Fri, 13 Dec 2024 23:16:44 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=9B=B4=E6=96=B0=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E6=9B=B4=E6=96=B0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E7=94=B1=E8=B7=AF=E5=BE=84=EF=BC=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BA=86=E9=87=8D=E8=BF=9E=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Util/util_pic.py | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/Util/util_pic.py b/Util/util_pic.py index e6ef291..ef39982 100644 --- a/Util/util_pic.py +++ b/Util/util_pic.py @@ -1,25 +1,33 @@ -import logging - -import PySide6 import cv2 -from PyQt5.QtGui import QImage, QPixmap - -from Util.util_log import log +from PIL.ImageQt import QImage, QPixmap 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 + height, width, channel = cv_img.shape + bytes_per_line = 3 * width + q_img = QImage(cv_img.data, width, height, bytes_per_line, QImage.Format_RGB888) + return QPixmap.fromImage(q_img) + +# def cv2_to_qpixmap(cv_img): +# """将OpenCV图像转换为QPixmap""" +# if len(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 +# def cv2_to_qpixmap(cv_img): +# #g = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB) +# height, width, channel = cv_img.shape +# bytes_per_line = 3 * width +# q_img = QImage(cv_img.data, width, height, bytes_per_line, QImage.Format_RGB888) +# return QPixmap.fromImage(q_img)