我是OpenCV和Qt的初学者,我的项目现在正在组合多个图像并将其显示在Qt Creator上。
#include <stdio.h>
#include <iostream>
#include <mutex>
#include <opencv2/opencv.hpp>
using namespace std;
int main(int argc, char** argv) {
string img_path = "/home/m/pictures/cat.jpg";
std::vector<cv::Mat> img_pool;
for (int i=0;i<10;i++)
{
cv::Mat data = cv::imread(img_path,-1);
img_pool.push_back(data);
}
cv::Mat data = cv::imread(img_path,-1);
cv::namedWindow("image", CV_WINDOW_NORMAL);
cv::imshow("image",data);
cv::waitKey(0);
cv::Mat data_dst = cv::Mat::zeros(500, 500, data.type());
cv::Mat data_resize;
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
cv::resize( img_pool[3], data_resize, cv::Size(50,50));
cv::Rect f_target(i*50,j*50,50,50);
data_resize.copyTo(data_dst(f_target));
}
}
cv::namedWindow("image_n", CV_WINDOW_NORMAL);
cv::imshow("image_n",data_dst);
cv::waitKey(0);
return 0;
}
结果如下:
我的代码现在可以显示一个图像,但我想要做的是显示不同的多个图像,我想我需要将图像或图像路径加载到矢量但我失败了,所以有人可以帮助我吗?
答案 0 :(得分:0)
您的代码中没有使用Qt。如果你想在Qt中使用这样的东西,你可以使用带有网格布局或flowlayout的简单小部件。然后从QImage数组中的路径加载所有图像并显示它。
您可以在此处找到FlowLayout的示例。您可以使用QLabel显示图像,将QImage转换为QPixmap并使用:
QImage yourImage("path");
QLabel image new QLabel(centralwidget);
imagelabel->setGeometry(QRect(20, 10, 371, 311));
imagelabel->setPixmap(QPixmap(QPixmap::fromImage(yourImage));
如果您是Qt的新手,可以使用FlowLayout和QML组件数组轻松地将其与QML集成。查看ImageViewer
的使用示例