Hello. I am creating a program with QT and using dlib for object detection. In some point I need to show an image via QT generated GUI, so I want to convert a dlib::array2d<dlib::rgb_pixel> to qt::QImage. Any suggestion on how to do that? I am stuck. An alternative could be conversion to Opencv image format, cv::Mat, and then converting cv::Mat to QImage, but I want to avoid that unnecesary step. Anyway, help converting dlib's format to cv::Mat will be apreciated too, I found in this forum information regarding only the inverse convertion.
Thanks in advance.</dlib::rgb_pixel>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To get pointer from array2d you can look into dlib/array2d/array2d_generic_image.h and use dlib::image_data function
QImage's constructor does not copy memory buffer, so you should make array2d to exists in memory until QImage's destructor called - QImage has cleanup function for it and you can find samples on stackoverflow
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello. I am creating a program with QT and using dlib for object detection. In some point I need to show an image via QT generated GUI, so I want to convert a dlib::array2d<dlib::rgb_pixel> to qt::QImage. Any suggestion on how to do that? I am stuck. An alternative could be conversion to Opencv image format, cv::Mat, and then converting cv::Mat to QImage, but I want to avoid that unnecesary step. Anyway, help converting dlib's format to cv::Mat will be apreciated too, I found in this forum information regarding only the inverse convertion.
Thanks in advance.</dlib::rgb_pixel>
You can use dlib::toMat() to convert to opencv. I've never used Qt's image
object so I don't know what you would use there.
Hi, you can use QImage contructor that creates image from memory buffer:
http://doc.qt.io/qt-5/qimage.html#QImage-6
To get pointer from array2d you can look into dlib/array2d/array2d_generic_image.h and use dlib::image_data function
QImage's constructor does not copy memory buffer, so you should make array2d to exists in memory until QImage's destructor called - QImage has cleanup function for it and you can find samples on stackoverflow
I don't know if you ever solved this but its probably because of the order of your #includes. Move all the opencv and dlib stuff before foundation.h
you can use https://github.com/mshobeyri/QFaceRecognition repo that is a qt/qml wrapper on dlib.