// read and resize images:filename,图片名称;savepath,保存压缩后的图片路径;l_side设定图片最长边大小;is_rgb,图片是否为彩色;img_num,处理第几张图片
int ReadImageToResize(const string& filename,const string& savepath,
const int l_side, const bool is_rgb, int img_num) {
cv::Mat cv_img; //存储压缩后的图片
//check rgb or gary
int cv_read_flag = (is_rgb ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE);
//read image
cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);
if (!cv_img_origin.data) {
std::cout << "Could not open or find the "<<img_num<<"th file :" << filename <<endl;
cv_img = cv_img_origin;
}
//获取图像的高和宽
int height = cv_img_origin.rows;
int width = cv_img_origin.cols;
//获取图像最大边长度
int long_side, short_side;
if(height > width){
long_side = height; //高为长边
short_side = width;
}else{
long_side = width; //宽为长边
short_side = height;
}
if(long_side/short_side >= 10) //如果长短边比例超过10:1,丢弃
return 0;
if ( long_
C++ 设定图像最大边长度并原比例压缩图片
最新推荐文章于 2022-02-25 15:52:40 发布