保存图像
//保存为png透明通道vector<int>opts;opts.push_back(IMWRITE_PAM_FORMAT_RGB_ALPHA);imwrite("D:/img_bgra.png", img, opts);//保存为单通道灰度图像img = cv::imread(imagePath.toStdString(), IMREAD_GRAYSCALE);vector<int> opts_gray;opts_gray.push_back(IMWRITE_PAM_FORMAT_GRAYSCALE);imwrite("D:/img_gray.png", img, opts_gray);//保存为默认的彩色BGR图像imwrite("D:/img_BGR.png", img);//保存为png彩色压缩图像img = imread(imagePath.toStdString(), IMREAD_ANYCOLOR);vector<int> opts_png_anycolor;opts_png_anycolor.push_back(IMWRITE_PAM_FORMAT_GRAYSCALE);opts_png_anycolor.push_back(9);imwrite("D:/img_png_anycolor.png", img, opts_png_anycolor);//保存为JPG高压缩比图像img = imread(imagePath.toStdString(), IMREAD_COLOR);vector<int> opts_jpeg;opts_jpeg.push_back(IMWRITE_JPEG_QUALITY);opts_jpeg.push_back(50);opts_jpeg.push_back(IMWRITE_JPEG_OPTIMIZE);//启用 JPEG 优化opts_jpeg.push_back(1);imwrite("D:/img_jpeg.jpg", img, opts_jpeg);
推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家:
零声白金学习卡(含基础架构/高性能存储/golang云原生/音视频/Linux内核)
https://xxetb.xet.tech/s/3Zqhgt