OpenCV 개요및설치 김성영교수 금오공과대학교 컴퓨터공학과
학습내용 OpenCV Library Introduction Installing OpenCV Library (Visual Studio 2010) Loading, displaying and saving images 주요자료구조 2
OpenCV Library Introduction open computer vision and machine learning software library developed by Intel, supported by Willow Garage and Itseez WebSite : http://opencv.org (http://docs.opencv.org) History Intel Research Project (1999) v1.0 (2006) Stable Release v2.4.2 (2012. 7. 4) Support OS : Windows, Linux, Mac, Android, ios Interface : C, C++, Python, JAVA(Android only) License : open source BSD License free for both academic & commercial use IPP(MMX, SSE), TBB, GPU(CUDA) support 3
Non-free functionality module SIFT : Scale-Invariant Feature Transform David G. Lowe, Distinctive Image Features from Scale-Invariant Keypoints, IJCV, 60(2), 2004 OpenCV Implementation : Rob Hess SURF : Speeded Up Robust Features Herbert Bay, Andreas Ess, Tinne Tuytelaars and Luc Van Gool, SURF: Speeded Up Robust Features, CVIU, Vol. 110, No. 3, pp. 346-359, 2008 OpenCV Implementation : Liu Liu 4
OpenCV 1.x C Interface 5
OpenCV 2.x C++ Interface Module core imgproc highgui video calib3d features2d objdetect ml flann gpu photo stitching nonfree contrib legacy Function The Core Functionality Image Processing High-level GUI and Media I/O Video Analysis Camera Calibration and 3D Reconstruction 2D Features Framework Object Detection Machine Learning Clustering and Search in Multi-Dimensional Spaces GPU-accelerated Computer Vision Computational Photography Images Stitching Non-free functionality Contributed / Experimental Stuff Deprecated Stuff 6
C:\opencv\samples\cpp C:\opencv\samples\cpp\tutorial_code edge.cpp contour2.cpp watershed.cpp dft.cpp 7
Installing OpenCV Library http://sourceforge.net/projects/opencvlibrary/files/ opencv-win/ 8
파일구성 C:\OpenCV 에압축해제 Third Party Code : OpenCV 라이브러리에서사용하는라이브러리 (JPEG, ffmpeg, TBB 등 ) Android용 OpenCV 응용프로그램코드플랫폼으로이미빌드된파일 CMake 설정파일 XML 학습데이터 OpenCV 문서들 : 사용자가이드, 참조문서, 튜토리얼, 로고등 include 헤더파일 ios(mac) 관련파일 OpenCV 모듈별소스코드 OpenCV 예제코드 9
10
path 설정 Windows XP 시작 내컴퓨터 속성 고급 환경변수 Path ; C:\opencv\build\x86\vc10\bin 11
Windows 7 시작 컴퓨터 속성 고급시스템설정 고급 환경변수 Path ; C:\opencv\build\x86\vc10\bin 12
tbb download http://threadingbuildingblocks.org/ver.php?fid=174 13
C:\tbb40_233oss\bin\ia32\vc10 Copy tbb.dll and tbb_debug.dll to C:\windows\system32 14
Loading, displaying and saving images 파일 새로만들기 프로젝트 File New Project Project OpenCVTest 15
콘솔응용프로그램 빈프로젝트 Console Application Empty Project 16
보기 속성관리자 View Property Manager 1. Right-clicking on Debug Win32 2. 새프로젝트속성시트추가 Add New Project Property Sheet OpenCV2_4ProjectD 17
포함디렉토리 Include Directories C:\OpenCV\build\include 18
라이브러리디렉토리 Library Directories C:\OpenCV\build\vc10\lib 19
추가종속성 Additional Dependencies opencv_calib3d242d.lib opencv_contrib242d.lib opencv_core242d.lib opencv_features2d242d.lib opencv_flann242d.lib opencv_gpu242d.lib opencv_haartraining_engine.lib opencv_highgui242d.lib opencv_imgproc242d.lib opencv_legacy242d.lib opencv_ml242d.lib opencv_nonfree242d.lib opencv_objdetect242d.lib opencv_photo242d.lib opencv_stitching242d.lib opencv_ts242d.lib opencv_video242d.lib opencv_videostab242d.lib 20
보기 솔루션탐색기 View Solution Explorer 1. Right-clicking on 소스파일Source Files 2. 추가 새항목 Add New Item main.cpp 21
#include "opencv/cv.h" #include "opencv/highgui.h" int main(void) { IplImage* pimage = cvloadimage( "lena.png", -1 ); if(pimage == NULL) return -1; cvnamedwindow( "Image", 1 ); cvshowimage( "Image", pimage ); cvwaitkey( 0 ); cvdestroywindow( "Image" ); cvreleaseimage( &pimage ); } return 0; 22
#include "opencv/cv.h" #include "opencv/highgui.h" int main(void){ IplImage* pimage = cvloadimage( "lena.jpg", -1 ); if(pimage == NULL) return -1; int param[3]; param[0] = CV_IMWRITE_JPEG_QUALITY; param[1] = 95; param[2] = 0; cvsaveimage( "result.jpg", pimage, param ); cvreleaseimage( &pimage ); } return 0; CV_IMWRITE_JPEG_QUALITY: 0 to 100 (better quality) CV_IMWRITE_PNG_COMPRESSION: 0 to 9 (smaller size) CV_IMWRITE_PXM_BINARY: 0 or 1 23
24
#include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" using namespace cv; int main(void) { Mat image = imread( "lena.jpg", -1 ); if(image.data == NULL) return -1; namedwindow( "Image" ); imshow( "Image", image ); waitkey( 0 ); } return 0; 25
#include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" using namespace cv; int main(void) { Mat image = imread( "lena.jpg", -1 ); if(image.data == NULL) return -1; vector<int> params; params.push_back( CV_IMWRITE_JPEG_QUALITY ); params.push_back( 95 ); imwrite( "result.jpg", image, params ); } return 0; CV_IMWRITE_JPEG_QUALITY: 0 to 100 (better quality) CV_IMWRITE_PNG_COMPRESSION: 0 to 9 (smaller size) CV_IMWRITE_PXM_BINARY: 0 or 1 26
주요자료구조 typedef struct _IplImage { int nsize; /* sizeof(iplimage) */ int ID; /* version (=0)*/ int nchannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */ int depth; /* pixel depth in bits */ int dataorder; /* 0 - interleaved color channels, 1 - separate color channels */ int origin; /* 0 - top-left origin, 1 - bottom-left origin (Windows bitmaps style) */ int align; /* Alignment of image rows (4 or 8). OpenCV ignores it and uses widthstep instead */ int width; /* image width in pixels */ int height; /* image height in pixels */ struct _IplROI *roi;/* image ROI */ int imagesize; /* image data size in bytes (=image->height*image->widthstep in case of interleaved data)*/ char *imagedata; /* pointer to aligned image data */ int widthstep; /* size of aligned image row in bytes */ char *imagedataorigin; /* pointer to a very origin of image data (not necessarily aligned) - it is needed for correct image deallocation */ } IplImage; 27
class CV_EXPORTS Mat { public: //... a lot of methods...... /*! includes several bit-fields: - the magic signature - continuity flag - depth - number of channels */ int flags; //! the array dimensionality, >= 2 int dims; //! the number of rows and columns int rows, cols; //! pointer to the data uchar* data; //! pointer to the reference counter; // when array points to user-allocated data, the pointer is NULL int* refcount; }; // other members... 28
Exercise 칼라영상을불러와서 split() 함수를이용하여영상을빨강, 녹색, 파랑채널 ( 평면 ) 로분리하여녹색영상만을화면에출력하시오. 29
#include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" using namespace cv; int main(void) { Mat image = imread( "color.png", -1 ); if(image.data == NULL) return -1; } vector<mat> mv; split( image, mv ); namedwindow( "Image" ); imshow( "Image", mv[1] ); waitkey( 0 ); return 0; 30
요약 OpenCV Library open computer vision and machine learning software library Installing OpenCV Library (Visual Studio 2010) Loading, displaying and saving images 주요자료구조 IplImage, Mat 31
Reference R. Laganière, OpenCV2 Computer Vision: Application Programming Cookbook, PACKT Publishing, 2011 G. Bradski and A. Kaebler, Learning OpenCV: Computer Vision with the OpenCV Library, O REILLY, 2008 정성환, 이문호, 오픈소스 OpenCV를이용한컴퓨터비전실무프로그래밍, 홍릉과학출판사, 2007 32