在opencv上压缩图像(imwrite).如何明确设置压缩系数? [英] Compressing images on opencv (imwrite). How to explicitly set the compression factor?

查看:296
本文介绍了在opencv上压缩图像(imwrite).如何明确设置压缩系数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在opencv上压缩图像时是否有一种方法可以轻松地指定压缩因子,而不必声明虚拟向量.如果我声明向量p(类似于此讨论),但仅包含2个项目,这是imwrite所需要的,我可以拨打电话:

I was wondering if there is a way to easily specify the compression factor when compressing images on opencv without having to declare a dummy vector. If I declare a vector p (similar to this discussion), but containing only 2 items, which is what imwrite takes, I can make the call:

vector<int> p(2);
p[0] = CV_IMWRITE_JPEG_QUALITY;
p[1] = 50; // compression factor

imwrite("compressed.jpg", img, p);

以上工作正常.但是,我想用一个循环中的几个压缩因子来压缩同一张图像.有没有一种方法可以显式地将参数传递给imwrite?像这样:

The above works fine. However, I want to compress the same image with several compression factors in a loop. Is there a way to explicitly pass the parameter to imwrite? Something like:

imwrite("compressed.jpg", img, {CV_IMWRITE_JPEG_QUALITY, factor}); // this doesn't work

仅需注意,函数标头为:

Just as a side note, the function header is:

bool imwrite(const string& filename, const Mat& img, const vector<int>& params=vector<int>());

谢谢!

更新:激活C ++ 0x之后,我可以将显式定义的内联向量传递给该函数.

Update: After activating C++0x, I can pass a vector explicitly defined inline to the function.

推荐答案

如建议的那样,激活C ++ 0x可使我将显式定义的向量直接传递给函数.这解决了问题.

As suggested, activating C++0x allows me to pass a vector explicitly defined inline to the function. This solved the issue.

这篇关于在opencv上压缩图像(imwrite).如何明确设置压缩系数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆