I have created a drawing application using Qt. Now, I whatever I draw, I need to process the image. So, I want to transfer the drawn image to Mat in openCV. How can I do that?
Asked
Active
Viewed 483 times
0
-
http://stackoverflow.com/questions/11886123/how-to-convert-qimage-to-opencv-mat – Mikołaj Mularczyk Sep 27 '14 at 14:59
1 Answers
1
I wrote code snippet for transfering screnshot to cv::Mat
, but I hope that you understand main idea, which conversation you should do.
QPixmap win = QPixmap::grabWindow(QApplication::desktop()->winId());
QImage scr = win.toImage().scaled(640,480);
QImage screen = scr.convertToFormat(QImage::Format_RGB888);
cv::Mat tmp(screen.height(),screen.width(),CV_8UC3,(uchar*)screen.bits(),screen.bytesPerLine());
cvtColor(tmp, tmp,CV_BGR2RGB);
Now cv::Mat
contains this image.
Example:
QPixmap okno = QPixmap::grabWindow(QApplication::desktop()->winId());
QImage scr = okno.toImage().scaled(640,480);
QImage screen = scr.convertToFormat(QImage::Format_RGB888);
cv::Mat tmp(screen.height(),screen.width(),CV_8UC3,(uchar*)screen.bits(),screen.bytesPerLine());
cvtColor(tmp, tmp,CV_BGR2RGB);
cv::namedWindow("d");
cv::imshow("d",tmp);
imshow
shows cv::Mat
properly.

Jablonski
- 18,083
- 2
- 46
- 47
-
Getting error, undefined reference to `cv::fastFree(void*)', undefined reference to `cv::Mat::deallocate()' – user3747190 Sep 27 '14 at 15:28
-
@user3747190 it isn't problem with my example code, something wrong with your project and all links given by google said that it is problem with linking libraries. – Jablonski Sep 27 '14 at 15:38