1. 在UI界面上放2個pushButton和2個label
2. 在QtGuiApplication1.h文件中添加槽相關代碼:
在QtGuiApplication1.cpp中添加槽函數。
3.添加信號和自定義槽
1)點擊編輯信號與槽按鈕進入編輯模式
2)在信號/槽編輯器中點擊+進行添加信號和槽,在槽中先選擇close()
3)然後回到ui界面,拖動槽到合適的位置,雙擊close(),如下圖所示出現配置連接
點擊編輯按鈕,在槽中添加自定義的槽函數,點擊OK
4)在UI界面中的文件下點擊保存
4. 點擊XXX.ui,右鍵選擇編譯,會在ui_seedingImageProcess.h中生成相應的代碼
修改界面,需要重新編譯。
Qt中顯示圖像:
Mat BGR 轉化爲RGB再轉化爲QImage格式,再用QPixmap對象獲得圖像,然後在Qlabel中顯示。
Mat srcImage, srcImage1, rgbImage;
QImage dstImage;
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), ".", tr("Image Files(*.jpg *.png *.jpeg *.bmp)"));
string str = fileName.toStdString();
if (fileName.isEmpty())
{
QMessageBox::information(this, "警告", "沒有選擇文件");
return;
}
srcImage = imread(str); //讀取圖片
cvtColor(srcImage, rgbImage, CV_BGR2RGB); //圖像格式轉換
dstImage = QImage((const unsigned char*)(rgbImage.data), rgbImage.cols, rgbImage.rows, QImage::Format_RGB888);
ui. label->setPixmap(QPixmap::fromImage(dstImage));//顯示