OpenCV/Patch to support WebP format on OpenCV 2.3.1

#multilang(ja){{

概要

OpenCV 2.3.1でWebP形式のフォーマットを扱えるようにするパッチです.
※OpenCV 2.3.1を対象としたパッチです.

ダウンロード

VersionFilenameSizeDateTypeDownload
1.0opencv2.3.1_webp_enable_patch_20111204.zip15.7 KB20111204ziphttp://www.atinfinity.info/opencv/extension/opencv2.3.1_webp_enable_patch_20111204.zip

変更履歴

VersionDate変更内容
1.020111204新規作成

使い方

OpenCV WebPパッチの適用

  1. 上記リンクからopencv2.3.1_webp_enable_patch_20111204.zipをダウンロードして展開します.
  2. 展開したmodulesディレクトリをOpenCVのmodulesディレクトリに上書きします.


Linux,Macに適用する場合には,パッチ(下記ファイル)の改行コードをあらかじめnkfコマンド等でLFに変換して下さい.

  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\include\opencv2\highgui\highgui_c.h
  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\src\grfmt_webp.cpp
  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\src\grfmt_webp.hpp
  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\src\grfmts.hpp
  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\src\loadsave.cpp

WebPライブラリのビルド

  1. こちらからWebPのソースをダウンロードします. ※検証にはアルファチャンネル付画像のエンコード,デコードが可能となったこちらを使用しました.
  2. libwebp-721f3f4.tar.gzを展開します.
  3. Visual Studio コマンド プロンプトを起動する.
  4. コマンド プロンプトでlibwebp-721f3f4のディレクトリに移動する.
  5. 下記のコマンドを実行する(release用ライブラリが生成される).
    nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output
  6. 同様に下記のコマンドを実行する(debug用ライブラリが生成される).
    nmake /f Makefile.vc CFG=debug-static RTLIBCFG=static OBJDIR=output
  7. libwebp-d71fbdc\output\release-static\x86\libにあるlibwebp_a.libをOpenCVの下記ディレクトリにコピーします.
    3rdparty\lib
  8. libwebp-d71fbdc\output\debug-static\x86\libにあるlibwebp_a_debug.libをOpenCVの下記ディレクトリにコピーします.
    3rdparty\lib
  9. libwebp-d71fbdc.tar\libwebp-d71fbdc\srcにあるwebpディレクトリをOpenCVの下記ディレクトリにコピーします.
    3rdparty\include

OpenCVのビルド

  1. OpenCVをCMakeを用いてビルドします.

おまけ

下記のような設定をすることでデコード時のquality(0~100)を指定できます.
※以下の例では最大品質の100を指定.

C API

int param[2];
param[0] = CV_IMWRITE_WEBP_QUALITY;
param[1] = 100;
cvSaveImage("img.webp", img, &param[0]);

C++ API

vector<int> param = vector<int>(2);
param[0]=CV_IMWRITE_WEBP_QUALITY;
param[1]=100;
imwrite("img.webp", img, param);

制限事項

  • Windows 32bitのみで動作検証.
  • 保存対象画像となるdepthは8Uのみです

注意点

  • CV_IMWRITE_WEBP_QUALITYによる指定が無い場合,デフォルトで95が指定されます.

参考情報

WebPConfigのpreset別パラメータ(個人用メモ).
こちらのソース上の値のため,今後変更される可能性があります.

WebPConfigInit?WEBP_PRESET_DEFAULTWEBP_PRESET_PHOTOWEBP_PRESET_PICTUREWEBP_PRESET_DRAWINGWEBP_PRESET_ICONWEBP_PRESET_TEXT
quality75XXXXXX
target_size0000000
target_PSNR0000000
method4444444
segments4444442
sns_strength505080802500
filter_strength202030351000
filter_sharpness0034600
filter_type0000000
autofilter0000000
pass1111111
show_compressed0000000
preprocessing0000000
partitions0000000
partition_limit0000000
alpha_compression1111111
alpha_quality100100100100100100100

※Xは初期化の際に指定したqualityの値が入ります. }}

#multilang(en){{

Abstract

This page describes the method to use WebP format on OpenCV 2.3.1.

Download

VersionFilenameSizeDateTypeDownload
1.0opencv2.3.1_webp_enable_patch_20111204.zip15.7 KB20111204ziphttp://www.atinfinity.info/opencv/extension/opencv2.3.1_webp_enable_patch_20111204.zip

ChangeLog?

VersionDateChanges
1.020111204First Release

Usage

Applying WebP patch

  1. Please download opencv2.3.1_webp_enable_patch_20111204.zip. And,extract this file.
  2. Please overwrite the patch's modules directory to OpenCV/modules.


If you want to apply this patch to OpenCV-2.3.1(Linux or Mac), please convert newline character of these file to LF from CRLF.

  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\include\opencv2\highgui\highgui_c.h
  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\src\grfmt_webp.cpp
  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\src\grfmt_webp.hpp
  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\src\grfmts.hpp
  • opencv2.3.1_webp_enable_patch_20111204\modules\highgui\src\loadsave.cpp

Build WebP library

  1. Please download WebP source code from Official Git page. I used this version's code for testing.
  2. Please extract libwebp-721f3f4.tar.gz.
  3. Please start Visual Studio command prompt.
  4. Please move to libwebp-721f3f4 directory.
  5. Please run the following command to make WebP library(release build).
    nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output
  6. Please run the following command to make WebP library(debug build).
    nmake /f Makefile.vc CFG=debug-static RTLIBCFG=static OBJDIR=output
  7. Please copy libwebp_a.lib to the following directory from libwebp-d71fbdc\output\release-static\x86\lib.
    3rdparty\lib
  8. Please copy libwebp_a_debug.lib to the following directory from libwebp-d71fbdc\output\debug-static\x86\lib
    3rdparty\lib.
  9. Please copy webp directory to the following directory from libwebp-d71fbdc.tar\libwebp-d71fbdc\src.
    3rdparty\include

Build OpenCV

  1. Please build OpenCV using CMake

Tips

You can specify the compression quality(min:0, max:100) by the following settings.

C API

int param[2];
param[0] = CV_IMWRITE_WEBP_QUALITY;
param[1] = 100;
cvSaveImage("img.webp", img, &param[0]);

C++ API

vector<int> param = vector<int>(2);
param[0]=CV_IMWRITE_WEBP_QUALITY;
param[1]=100;
imwrite("img.webp", img, param);

Limitation

  • I have only tested this environment.
    • Windows 32bit
  • Save image depth supports 8U only.

Notes

  • If you does not specify the quality by CV_IMWRITE_WEBP_QUALITY, 95 is specified by default. }}

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2012-01-03 (火) 20:56:00 (4490d)