OpenCV/Patch to support WebP format on OpenCV 2.3.1 †
#multilang(ja){{
概要 †
OpenCV 2.3.1でWebP形式のフォーマットを扱えるようにするパッチです.
※OpenCV 2.3.1を対象としたパッチです.
ダウンロード †
Version | Filename | Size | Date | Type | Download |
1.0 | opencv2.3.1_webp_enable_patch_20111204.zip | 15.7 KB | 20111204 | zip | |
変更履歴 †
Version | Date | 変更内容 |
1.0 | 20111204 | 新規作成 |
使い方 †
OpenCV WebPパッチの適用 †
- 上記リンクからopencv2.3.1_webp_enable_patch_20111204.zipをダウンロードして展開します.
- 展開した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ライブラリのビルド †
- こちらからWebPのソースをダウンロードします.
※検証にはアルファチャンネル付画像のエンコード,デコードが可能となったこちらを使用しました.
- libwebp-721f3f4.tar.gzを展開します.
- Visual Studio コマンド プロンプトを起動する.
- コマンド プロンプトでlibwebp-721f3f4のディレクトリに移動する.
- 下記のコマンドを実行する(release用ライブラリが生成される).
nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output
- 同様に下記のコマンドを実行する(debug用ライブラリが生成される).
nmake /f Makefile.vc CFG=debug-static RTLIBCFG=static OBJDIR=output
- libwebp-d71fbdc\output\release-static\x86\libにあるlibwebp_a.libをOpenCVの下記ディレクトリにコピーします.
3rdparty\lib
- libwebp-d71fbdc\output\debug-static\x86\libにあるlibwebp_a_debug.libをOpenCVの下記ディレクトリにコピーします.
3rdparty\lib
- libwebp-d71fbdc.tar\libwebp-d71fbdc\srcにあるwebpディレクトリをOpenCVの下記ディレクトリにコピーします.
3rdparty\include
OpenCVのビルド †
- OpenCVをCMakeを用いてビルドします.
おまけ †
下記のような設定をすることでデコード時のquality(0~100)を指定できます.
※以下の例では最大品質の100を指定.
C API †
int param[2];
param[0] = CV_IMWRITE_WEBP_QUALITY;
param[1] = 100;
cvSaveImage("img.webp", img, ¶m[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_DEFAULT | WEBP_PRESET_PHOTO | WEBP_PRESET_PICTURE | WEBP_PRESET_DRAWING | WEBP_PRESET_ICON | WEBP_PRESET_TEXT |
quality | 75 | X | X | X | X | X | X |
target_size | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
target_PSNR | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
method | 4 | 4 | 4 | 4 | 4 | 4 | 4 |
segments | 4 | 4 | 4 | 4 | 4 | 4 | 2 |
sns_strength | 50 | 50 | 80 | 80 | 25 | 0 | 0 |
filter_strength | 20 | 20 | 30 | 35 | 10 | 0 | 0 |
filter_sharpness | 0 | 0 | 3 | 4 | 6 | 0 | 0 |
filter_type | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
autofilter | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
pass | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
show_compressed | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
preprocessing | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
partitions | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
partition_limit | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
alpha_compression | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
alpha_quality | 100 | 100 | 100 | 100 | 100 | 100 | 100 |
※Xは初期化の際に指定したqualityの値が入ります.
}}
#multilang(en){{
Abstract
This page describes the method to use WebP format on OpenCV 2.3.1.
Download
Version | Filename | Size | Date | Type | Download |
1.0 | opencv2.3.1_webp_enable_patch_20111204.zip | 15.7 KB | 20111204 | zip | |
ChangeLog?
Version | Date | Changes |
1.0 | 20111204 | First Release |
Usage
Applying WebP patch
- Please download opencv2.3.1_webp_enable_patch_20111204.zip. And,extract this file.
- 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
- Please download WebP source code from Official Git page. I used this version's code for testing.
- Please extract libwebp-721f3f4.tar.gz.
- Please start Visual Studio command prompt.
- Please move to libwebp-721f3f4 directory.
- Please run the following command to make WebP library(release build).
nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output
- Please run the following command to make WebP library(debug build).
nmake /f Makefile.vc CFG=debug-static RTLIBCFG=static OBJDIR=output
- Please copy libwebp_a.lib to the following directory from libwebp-d71fbdc\output\release-static\x86\lib.
3rdparty\lib
- Please copy libwebp_a_debug.lib to the following directory from libwebp-d71fbdc\output\debug-static\x86\lib
3rdparty\lib.
- Please copy webp directory to the following directory from libwebp-d71fbdc.tar\libwebp-d71fbdc\src.
3rdparty\include
Build OpenCV
- 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, ¶m[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.
- Save image depth supports 8U only.
Notes
- If you does not specify the quality by CV_IMWRITE_WEBP_QUALITY, 95 is specified by default.
}}