問題描述
我想知道如何將 OpenCV C++ 標(biāo)準(zhǔn) cv::Mat 類型轉(zhuǎn)換為 QImage.我一直在四處尋找,但沒有運(yùn)氣.我發(fā)現(xiàn)了一些將 IPlimage 轉(zhuǎn)換為 QImage 的代碼,但這不是我想要的.謝謝.
I am wondering how would I convert the OpenCV C++ standard cv::Mat type to QImage. I have been searching around, but have no luck. I have found some code that converts the IPlimage to QImage, but that is not what I want. Thanks.
推薦答案
Michal Kottman 的回答是有效的,并且對某些圖像給出了預(yù)期的結(jié)果,但在某些情況下會失敗.這是我找到的解決該問題的方法.
Michal Kottman's answer is valid and give expected result for some images but it'll fail on some cases. Here is a solution i found to that problem.
QImage imgIn= QImage((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);
不同之處在于添加了 img.step 部分.沒有它,qt 不會抱怨,但如果沒有它,某些圖像將無法正常顯示.希望這會有所幫助.
Difference is adding img.step part. qt won't complain without it but some images won't show properly without it. Hope this will help.
這篇關(guān)于如何將 OpenCV cv::Mat 轉(zhuǎn)換為 QImage的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!