OpenCVについて
OpenCVとはOpen Source Computer Vision Libraryのことです。主にintelが開発しています。
画像処理を行なう為に必要な基本的な処理、各種フォーマットの画像入出力関数、基本的な画像処理関数などが提供されています。特に入出力関連機能は強力で、一般的なフォーマットの画像はもちろんのこと、USB接続したカメラから直接的に画像/動画を取り込むことが可能です。
インストール方法
Windows
Linux
Debian GNU/Linuxの場合は
$ apt-cache search opencv
とすると
libcv-dev - development files for libcv libcv0.9.7-0 - computer vision library libcvaux-dev - development files for libcvaux libcvaux0.9.7-0 - computer vision extension library libhighgui-dev - development files for libhighgui libhighgui0.9.7-0 - computer vision GUI library opencv-doc - OpenCV documentation and examples python-opencv - Python bindings for the computer vision library
のように必要なパッケージが出てくるはずなので,これらのパッケージをインストールして下さい.
Mac OS X
まずパッケージシステムのfinkをインストールします。次に各種画像ライブラリをインストールします。ターミナルで
$ fink install libjpeg $ fink install libpng3 $ fink install libtiff
として、次にffmpegを手に入れます。ターミナルで
$ curl -O http://www.isquint.org/iSquint1.4.3.dmg $ open iSquint1.4.3.dmg $ sudo cp /Volumes/iSquint/iSquint.app/Contents/Resources/ffmpeg /usr/local/bin/
次にOpenCVのソースコードを入手します。
$ cvs -z3 -d:pserver:anonymous@opencvlibrary.cvs.sourceforge.net:/cvsroot/opencvlibrary co -P opencv
次にmake
$ ./configure CPPFLAGS="-I/sw/include" LDFLAGS="-L/sw/lib" $ make $ sudo make install
sampleの動かし方
$ cd ./opencv/samples/c/
として、ここにbuild_all.shがあるので
$ ./build_all.sh
でビルド出来ます。
基本的な使い方
ラスタースキャン。
#include <stdio.h>
#include "cv.h"
#include "highgui.h"
int main ( int argc, char *argv[] )
{
int i, j, k;
IplImage* img = cvLoadImage( 'lena.png', -1 );
for( k=0; k<img->nChannels; k++ ){
for( i=0; i<img->height; i++ ){
for( j=0; j<img->width; j++ ){
printf( "%d\n", (unsigned char)img->imageData[i*img->widthStep+j*img->nChannels+k] );
}
}
}
}便利な参考書