如何将使用Qt Paint Application绘制的图像传输到Mat openCV

How to transfer the image drawn using Qt Paint Application to Mat openCV

本文关键字:图像 传输 openCV Mat 绘制 Application Paint Qt      更新时间:2023-10-16

我已经使用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);

CCD_ 3正确地显示了CCD_ 4。