1.第一种方法
用OpenCV中的函数cvSaveImage(filename,img)来保存图像,很少注意到它还有第三个参数。第三个参数就是用来调整JPG图像压缩质量的,它是一个含有3个元素的数组,具体使用方法如下:
#define CV_IMWRITE_JPEG_QUALITY 1#define CV_IMWRITE_PNG_COMPRESSION 16#define CV_IMWRITE_PXM_BINARY 32 /* save image to file */ CVAPI(int) cvSaveImage( const char* filename, const CvArr* image, const int* params CV_DEFAULT(0) ); int p[3]; p[0] = CV_IMWRITE_JPEG_QUALITY; p[1] = desired_quality_value; p[2] = 0;
#include <opencv2\opencv.hpp> #include<iostream>#include <stdio.h>using namespace cv;int main(int argc, char **argv){int p[3];IplImage *img = cvLoadImage("test.jpg");p[0] = CV_IMWRITE_JPEG_QUALITY;p[1] = 10;p[2] = 0;cvSaveImage("p1.jpg", img, p);p[0] = CV_IMWRITE_JPE
如果觉得《利用OpenCV保存图片 提高压缩质量》对你有帮助,请点赞、收藏,并留下你的观点哦!