我已经使用Qt创建了一个绘图应用程序。现在,无论我画什么,我都需要处理图像。因此,我想在openCV中将绘制的图像传输到Mat。我怎样才能做到这一点?
我编写了将screnshot传输到的代码段cv::Mat
,但希望您了解主要思想,应该进行哪种对话。
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);
现在cv::Mat
包含此图像。
例子:
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
cv::Mat
正确显示。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句