我正在尝试将图像放置在我的 openCV 代码中的标签中。opencv 部分运行顺畅。然而,显示 Qimage 被证明是一个问题。我将图像放在标签中。
ui->lblOriginal->setPixmap(QPixmap::fromImage(qimgOriginal));
但是,它告诉我“错误:C2039:'lblOriginal':不是'Ui :: Dialog'的成员”
lblOriginal 是我对话框中的一个标签。有什么我想念的吗?这是 dialog.cpp 中的完整代码:
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
capWebcam.open(0);
tmrTimer = new QTimer(this);
connect(tmrTimer, SIGNAL(timeout()), this, SLOT(processAndUpdateGUI()));
tmrTimer->start(20);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::processAndUpdateGUI(){
capWebcam >> matOriginal;
if(matOriginal.empty() == true)return;
cv::cvtColor(matOriginal,matOriginal, CV_BGR2RGB);
QImage qimgOriginal((uchar*)matOriginal.data, matOriginal.cols, matOriginal.rows,matOriginal.step,QImage::Format_RGB888);
ui->lblOriginal->setPixmap(QPixmap::fromImage(qimgOriginal));
}
我们的 xml 文件如下。
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1181</width>
<height>590</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="lblOrignal">
<property name="geometry">
<rect>
<x>80</x>
<y>36</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>