How to convert QImage to opencv Mat

前端 未结 5 1533
一个人的身影
一个人的身影 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

    One year after you issued this question there've been great answers on the internet:

    • Convert between cv::mat and Qimage correctly
    • Converting Between cv::Mat and QImage or QPixmap

    But the way I see it, if you're working with Qt and OpenCV at the same time then type QImage is probably just for displaying, that case you might want to use QPixmap since it's optimized for displaying. So this is what I do:

    1. Load image as cv::Mat, if you'd like to display the image, convert to QPixmap using the non-copy method introduced in the second article.
    2. Do your image processing in cv::Mat.
    3. Any time during the workflow you can call upon something like Mat2QPixmap() to get realtime result.
    4. Never convert QPixmap to cv::Mat, there's no sense doing it considering the purpose of each type.

提交回复
热议问题