How to convert QImage to opencv Mat

前端 未结 5 1538
一个人的身影
一个人的身影 2020-12-14 12:38

I have searched on the internet but I cannot find a method of converting a QImage(or QPixmap) to a OpenCV Mat. How would I do this?.

5条回答
  •  忘掉有多难
    2020-12-14 13:15

    The answer to this with Qt 5.11 (and probably some earlier versions):

        cv::Mat mat(image.height(), image.width(),CV_8UC3, image.bits());  
        // image.scanline() does not exist, 
        //and height/width is interchanged for a matrix
    

    Again the QImage is assumed to be RGB888 (ie QImage::Format_RGB888)

提交回复
热议问题