PyQt/PySide: How do I convert QImage into OpenCV's MAT format

后端 未结 2 568
广开言路
广开言路 2021-01-03 09:04

I\'m looking to create a function for converting a QImage into OpenCV\'s (CV2) Mat format from within the PyQt.

How do I do this? My input images I\'ve been working

2条回答
  •  旧时难觅i
    2021-01-03 09:51

    I tried the answer given above, but couldn't get the expected thing. I tried this crude method where i saved the image using the save() method of the QImage class and then used the image file to read it in cv2

    Here is a sample code

    def qimg2cv(q_img):
        q_img.save('temp.png', 'png')
        mat = cv2.imread('temp.png')
        return mat
    

    You could delete the temporary image file generated once you are done with the file. This may not be the right method to do the work, but still does the required job.

提交回复
热议问题