本博客主要记录自己平时查找的图像处理的方法。
1、读入本地图像,提取单通道图像,截取ROI区域,保存图像
//读入图像
Mat img = imread("./dataset/imgpictures_car1/00497.jpg");
//提取单通道图
vector<Mat> channels;
split(img, channels);
imgSingle = channels.at(1);
//截取ROI区域
//Rect(rect.x, rect.y, rect.width, rect.height)
Mat roi;
Rect rect;
roi = imgSingle(Rect(x,y,height,width));
//保存图像
int k = 0;
imwrite("D:\\WorkSpace\\QTProject\\TestFODReportTwo\\resultimg\\" +to_string(k)+".jpg",roi);
2、QImage转QByteArray
QBuffer buffer;
buffer.open(QIODevice::ReadWrite);
QImage pixmap("monkey.jpg");
//pixmap不能为空,必须先将图片加载到pixmap中
pixmap.save(&buffer,"jpg");
QByteArray pixArray;
pixArray.append(buffer.data());
但是pixArray的大小size不等于QImage.height*QImage.width。这个地方还没有弄明白,日后补充。
3、QT中读取本地文件夹中的图片,并在QLable中显示
//--------------读取本地文件夹中的图像,并在QT界面上显示-------------//
#include <io.h> //for _finddata_t
#include <cstring> //for strcat_s
//本地文件夹所在路径
char path[150] = "./dataset/init_img/";
strcat_s(path, "*.jpg");
long long handle;
struct _finddata_t fileinfo;
handle = _findfirst(path, &fileinfo);
if (-1 == handle)
qDebug()<<-1;
printf("%s\n", fileinfo.name);
Mat frame;
do
{
char filename[150] = "./dataset/init_img/";
strcat_s(filename, fileinfo.name);
//读入图片,存入到frame中
frame = cv::imread(filename,cv::IMREAD_GRAYSCALE);
//将Mat格式的图片在QLable显示
QImage Q_input_Img = MattoQImage.Mat2QImage(frame);
const QSize s_input = ui->label_displayImg->size() ;
ui->label_displayImg->setPixmap( QPixmap::fromImage( Q_input_Img ).scaled(s_input,Qt::KeepAspectRatio ) );
}while (!_findnext(handle, &fileinfo));
4、QT读取本地txt图像数据并在界面上显示该图像
链接:https://blog.youkuaiyun.com/weixin_38621214/article/details/84640268
5、QT将图像数据写入txt文档
链接:https://blog.youkuaiyun.com/weixin_38621214/article/details/84640372