OpenCV cvSaveImage Jpeg压缩因子 [英] OpenCV cvSaveImage Jpeg Compression Factor

查看:499
本文介绍了OpenCV cvSaveImage Jpeg压缩因子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OpenCV和保存为jpeg使用cvSaveImage函数,但我无法找到使用的Jpeg压缩因子。

I am using OpenCV and saving as a jpeg using the cvSaveImage function, but I am unable to find the Jpeg compression factor used by this.


  1. 什么是cvSaveImage(...)的Jpeg压缩因子

  2. 如何通过使用cvSaveImage(...)时的压缩系数


推荐答案

目前cvSaveImage只需要两个参数:

Currently cvSaveImage() is declared to take only two parameters:

int cvSaveImage( const char* filename, const CvArr* image );

但是,最新测试快照has:

  #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值数组以传递第三个参数:

I've been unable to find any documentation, but my impression from poking through this code is that you would build an array of int values to pass in the third parameter:

int p[3];
p[0] = CV_IMWRITE_JPEG_QUALITY;
p[1] = desired_quality_value;
p[2] = 0;

我不知道质量值是如何编码的,我从来没有尝试过,警告。

I don't know how the quality value is encoded, and I've never tried this, so caveat emptor.

编辑

下载并构建了OpenCV的最新中继版本,并且能够通过这一点一次性代码确认以上内容:

Being a bit curious about this, I downloaded and built the latest trunk version of OpenCV, and was able to confirm the above via this bit of throwaway code:

#include "cv.h"
#include "highgui.h"
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("out1.jpg", img, p);

    p[0] = CV_IMWRITE_JPEG_QUALITY;
    p[1] = 100;
    p[2] = 0;

    cvSaveImage("out2.jpg", img, p);

    exit(0);
}



我的test.jpg为2,054 KB,创建的out1.jpg 是182 KB,out2.jpg是4,009 KB。

My "test.jpg" was 2,054 KB, the created "out1.jpg" was 182 KB and "out2.jpg" was 4,009 KB.

看起来你应该是在良好的形状,假设你可以使用Subversion存储库中提供的最新代码。

Looks like you should be in good shape assuming you can use the latest code available from the Subversion repository.

BTW,质量参数的范围为0-100,默认为95.

BTW, the range for the quality parameter is 0-100, default is 95.

这篇关于OpenCV cvSaveImage Jpeg压缩因子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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