在Python中将OpenCV 3(iplImage)转换为PyQt5 QImage / QPixmap

时间:2015-11-16 18:13:01

标签: python opencv pyqt5 qimage qpixmap

在此问题被驳回之前,请注意:

  • 使用OpenCV版本3(不是版本2)
  • 使用Python 3(不是C ++)
  • 使用PyQt 5(不是PyQt4)

目标:尝试在PyQt5 GUI窗口中传输OpenCV网络摄像头视频帧

import os
import os    

def diff_dir_with_filelist(directory, filepath):
    new_files =  os.listdir(directory)
    with open(filepath, 'r') as text_file:
        old_list = text_file.readlines()

    old_files = set(item.rstrip() for item in old_list)
    return [x for x in new_files if x not in old_files]

results = diff_dir_with_filelist("C:\\Users\\INstokes\\Desktop\\CityPts\\", "C:\\Users\\INstokes\\Desktop\\CityPts\\file.txt")
print(results)

我不知道如何调试它。没有错误回溯打印到控制台。任何帮助表示赞赏。提前谢谢。

1 个答案:

答案 0 :(得分:1)

首先需要将openCv图像转换为QImage,然后使用pixmap显示图像,因为pixmap支持QImage格式。

   height, width, bytesPerComponent = Img.shape
   bytesPerLine = 3 * width
   cv2.cvtColor(Img, cv2.COLOR_BGR2RGB, Img)                                           
   QImg = QImage(Img.data, width, height, bytesPerLine,QImage.Format_RGB888)

现在使用此QImg来pixmap

   pixmap = QPixmap.fromImage(QImg)
相关问题