Read an image in Ressources QT


I use QT and OpenCV. How to specify an image resource file when I use imread instead of the path of the image ?


You probably mean Qt. You really have a Qt question here, not an OpenCV question.

As imread() apparently can’t understand the Qt resources, you need to copy the file from resources to the file system, with QFile or something.

dumping to file is bad. it’s roundabout.

I’d rather recommend that you use Qt APIs to read the resource as a QBitmap or whatever they use, and then, if you need that as a cv::Mat, use a suitable cv::Mat constructor given the bitmap data you just loaded using Qt APIs.

if you can get Qt to decode the image file into a bitmap, that’s best. if you can only get the bytes of the encoded file, you can use cv::imdecode to decode it.