// GTImageCompress.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include "opencv/cv.h"
#include "opencv2\opencv.hpp"
#if _DEBUG
#pragma comment(lib,"opencv_world349d.lib")
#else
#pragma comment(lib,"opencv_world349.lib")
#endif
int main()
{
cv::Mat src = cv::imread("28002.bmp");
if (src.data != NULL)
{
std::vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(10); //图像压缩参数,该参数取值范围为0-100,数值越高,图像质量越高
//bool bRet = imwrite("test2.jpg", src, compression_params);
std::vector<uchar> vecResult;
clock_t start, stop;//定义clock_t类型的start和end
start = clock();
bool bRet = imencode(".bmp", src, vecResult);
stop = clock();
printf("%f\n", (double)(stop - start) / CLOCKS_PER_SEC);
if (bRet)
{
std::cout << "图像保存成功" << std::endl;
}
else
{
std::cout << "图像保存失败" << std::endl;
}
}
else
{
std::cout << "图片加载失败,请检查文件是否存在!" << std::endl;
}
//cv::waitKey(0);
getchar();
return 0;
}
图像文件压缩
最新推荐文章于 2022-08-08 21:53:10 发布