imwrite
1.JPG格式图片是自带压缩的
IMWRITE_JPEG_QUALITY | For JPEG, it can be a quality from 0 to 100 (the higher is the better). Default value is 95. |
IMWRITE_JPEG_PROGRESSIVE Python: cv.IMWRITE_JPEG_PROGRESSIVE | Enable JPEG features, 0 or 1, default is False. |
IMWRITE_JPEG_OPTIMIZE Python: cv.IMWRITE_JPEG_OPTIMIZE | Enable JPEG features, 0 or 1, default is False. |
IMWRITE_JPEG_RST_INTERVAL Python: cv.IMWRITE_JPEG_RST_INTERVAL | JPEG restart interval, 0 - 65535, default is 0 - no restart. |
IMWRITE_JPEG_LUMA_QUALITY Python: cv.IMWRITE_JPEG_LUMA_QUALITY | Separate luma quality level, 0 - 100, default is -1 - don't use. |
IMWRITE_JPEG_CHROMA_QUALITY Python: cv.IMWRITE_JPEG_CHROMA_QUALITY | Separate chroma quality level, 0 - 100, default is -1 - don't use. |
IMWRITE_JPEG_SAMPLING_FACTOR Python: cv.IMWRITE_JPEG_SAMPLING_FACTOR | For JPEG, set sampling factor. See cv::ImwriteJPEGSamplingFactorParams. |
2.bmp格式图片是不带任何压缩
3.PNG格式保存图像的质量是最接近原本质量的,但保存写入的速度是最慢的。
IMWRITE_PNG_COMPRESSION | For PNG, it can be the compression level from 0 to 9. A higher value means a smaller size and longer compression time. If specified, strategy is changed to IMWRITE_PNG_STRATEGY_DEFAULT (Z_DEFAULT_STRATEGY). Default value is 1 (best speed setting). |
IMWRITE_PNG_STRATEGY | One of cv::ImwritePNGFlags, default is IMWRITE_PNG_STRATEGY_RLE. |
IMWRITE_PNG_BILEVEL | Binary level PNG, 0 or 1, default is 0. |
double t1 = (double)getTickCount();double t2 = 0; std::vector<int> params;params.push_back(cv::IMWRITE_JPEG_QUALITY);params.push_back(10);//params.push_back(50);//params.push_back(100);cv::imwrite("C:\\test.jpg", image, params);t2 = ((double)getTickCount() - t1) / getTickFrequency();cout << "time:" << t2 << endl;
测试结果:
原图大小39.1 MB
quality 10:保存图像大小228K
quality 50:保存图像大小342K
quality 100:保存图像大小6.65M