1 / 29

Multimedia Programming 03: 점 , 선 , 면

Multimedia Programming 03: 점 , 선 , 면. Departments of Digital Contents Sang Il Park. Review: OpenCV 초기 세팅. 필요한 디렉토리 세팅 Includes: "C: OpenCV-2.3.0 include" Libraries: "C: OpenCV-2.3.0 lib“ 필요한 라이브러리 파일들 세팅 : opencv_core230.lib opencv_imgproc230.lib opencv_highgui230.lib.

dillon
Télécharger la présentation

Multimedia Programming 03: 점 , 선 , 면

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Multimedia Programming 03:점, 선, 면 Departments of Digital Contents Sang Il Park

  2. Review: OpenCV 초기 세팅 • 필요한 디렉토리 세팅 • Includes: • "C:\OpenCV-2.3.0\include" • Libraries: • "C:\OpenCV-2.3.0\lib“ • 필요한 라이브러리 파일들 세팅: • opencv_core230.lib • opencv_imgproc230.lib • opencv_highgui230.lib

  3. Today, we will learn: • IplImage 구조체 • OpenCV 익숙해 지기 • 점 • 선 • 면

  4. HelloCV http://dasan.sejong.ac.kr/~sipark/class2011/mm/code/hellocv.cpp • IplImage • cvLoadImage • cvReleaseImage • cvNamedWindow • cvShowImage • cvDestroyWindow • cvWaitKey #include <opencv2/opencv.hpp> int main() { IplImage * img; img = cvLoadImage(“c:\\test.jpg"); cvNamedWindow("HelloCV"); cvShowImage("HelloCV", img); cvWaitKey(); cvDestroyWindow("HelloCV"); cvReleaseImage(&img); return 0; }

  5. Image structure (이미지 구조체) • IplImage (Image Processing Library) • typedef struct _IplImage { int nSize; /* size of iplImage struct */ int ID; /* image header version */ int nChannels; int alphaChannel; int depth; /* pixel depth in bits */ char colorModel[4]; char channelSeq[4]; int dataOrder; int origin; int align; /* 4- or 8-byte align */ int width; int height; struct _IplROI *roi; /* pointer to ROI if any */ struct _IplImage *maskROI; /*pointer to mask ROI if any */ void *imageId; /* use of the application */ struct _IplTileInfo *tileInfo; /* contains information on tiling*/ int imageSize; /* useful size in bytes */ char *imageData; /* pointer to aligned image */ int widthStep; /* size of aligned line in bytes */ int BorderMode[4]; /* the top, bottom, left, and right border mode */ int BorderConst[4]; /* constants for the top, bottom,left, and right border */ char *imageDataOrigin; /* ptr to full, nonaligned image */} IplImage;

  6. 구조체 (structure) ? • 하나의 물건(객체)가 여러 요소로 구성되어 있을때 효율적으로 표현하기 • Example) • 학생: 이름, 학번, 주소, 전화번호,… • 성적: 국어점수, 수학점수, 영어점수, 총점, 평균 구조체: 관련된 정보를 그룹화하여 표현

  7. 구조체 (structure) 구조체: 관련된 정보를 그룹화하여 표현 구조체 이름 학생 이름 학번 주소 전화번호 멤버 변수

  8. 구조체의 정의 • Example) • struct student • { • char name[30]; • int number; • float grade; • };

  9. 멤버로의 접근 구조체변수이름.맴버변수이름 • struct score • { • int korean; • int math; • }; • score a; • a.korean = 30; • a.math = 80;

  10. Image structure (이미지 구조체) • IplImage (Image Processing Library) • struct IplImage { int nSize; /* size of iplImage struct */ int ID; /* image header version */ int nChannels; int alphaChannel; int depth; /* pixel depth in bits */ char colorModel[4]; char channelSeq[4]; int dataOrder; int origin; int align; /* 4- or 8-byte align */ int width; int height; struct _IplROI *roi; /* pointer to ROI if any */ struct _IplImage *maskROI; /*pointer to mask ROI if any */ void *imageId; /* use of the application */ struct _IplTileInfo *tileInfo; /* contains information on tiling*/ int imageSize; /* useful size in bytes */ char *imageData; /* pointer to aligned image */ int widthStep; /* size of aligned line in bytes */ int BorderMode[4]; /* the top, bottom, left, and right border mode */ int BorderConst[4]; /* constants for the top, bottom,left, and right border */ char *imageDataOrigin; /* ptr to full, nonaligned image */};

  11. Image I/O (이미지 입출력) • IplImage* cvLoadImage(image_path); 파일로 부터 이미지를 읽는다. 성공할 경우 메모리가 생성되고 IplImage pointer를반환실패할 경우 NULL 값을 리턴 • cvSaveImage(image_path, IplImage *); 이미지를 파일로 저장한다. 형식은 확장자로 부터 결정 • cvReleaseImage(IplImage **);이미지를 저장하고 있던 메모리를 해제한다. • BMP, JPEG, PNG, TIFF, PPM/PGM 포멧등이 지원됨

  12. Image I/O (이미지 입출력) • 이미지의 포멧을 바꾸어 저장하기 예: IplImage* img = cvLoadImage(“picture.jpg”); if( img != NULL ) cvSaveImage( “picture.bmp”, img );

  13. Windows • cvNamedWindow(window_name); 윈도우를 생성한다. 윈도우는 이름을 부여할 수 있고, 각 이름을 기준으로 구분한다. cvNamedWindow(“ViewA”); cvMoveWindow(“ViewA”,300,100); cvDestroyWindow(“ViewA”); … • cvShowImage(window_name, IplImage *); 주어진 이름에 해당하는 윈도우에 이미지를 보여준다. 한 이미지만을 보여 줄 수 있으며, 부분 적인 출력은 하지 못한다. • cvDestroyWindow(window_name);주어진 이름에 해당하는 윈도우를 없앤다.

  14. User Input • int cvWaitKey( int delay=0 )사용자가 키를 누르기를 정해진 대기시간 만큼 기다린다. 대기시간이 초과되면 다음 명령을 수행한다. 대기시간으로 0을 설정하면 영원히 기다린다. • 시간의 값은 millisecond  대기시간을 이용하면 애니메이션을 만들 수 있다. • 활용예) 두 개 이상의 그림을 교대로 보여줌

  15. Image and Pixel

  16. 픽셀(Pixel: Picture Element) • 이미지:픽셀의 집합 • 비트맵(Bitmap)

  17. 픽셀 • 픽셀의 색: 적색(Red), 녹색(Green), 청색(Blue) • 컬러의 수 픽셀 당 비트 수(밝기 레벨)

  18. Pixel의 값 = (위치, 색) • 위치 : 각 픽셀의 2D 좌표 (Image Coordinate System) • 색 : CvScalar(색을 저장하는 구조체) x (0,0) (8,2) y

  19. 색을 저장하는 변수: CvScalar • 4 개 이하의 숫자를 저장할 수 있도록 만든 구조체 • 0번은 blue, 1번은 green, 2번은 red 값을 저장 • Example) CvScalar s; s.val[0] = 200; (Blue) s.val[1] = 11; (Green) s.val[2] = 123; (Red) • struct CvScalar { double val[4]; };

  20. 이미지에서 Pixel값으로의 접근 • CvScalar cvGet2D (IplImage*, y, x) (x,y)에서의 칼라 값 얻기. • Example) CvScalar s; s = cvGet2D(img, 30, 40); • void cvSet2D(IplImage*, y, x, CvScalar) (x,y)에서의 칼라 값 변경 • Example) CvScalar s = cvScalar(100,0,0); cvSet2D(img, 30, 40, s);또는 cvSet2D(img, 30, 40, cvScalar(100,0,0)); 주의: 반드시 x,y는 이미지 범위 내부에 있어야함! (image의 width와 height를 정보를 참조할것)

  21. 코딩연습 • 이미지의 일부를 Gray-scale image로만들기 • Gray 이미지: 각 픽셀마다 R, G, B 값이 모두 같은 이미지 • 칼라 이미지의 각 pixel의 R, G, B 값으로 부터 대표값(=평균값)을 얻는다 • 더 생각해 볼 문제: • 이미지의 일부를 흑백 이미지로 만들기

  22. 생각해 보기: Sepia image 만들기

  23. 빈 이미지 생성하기 • IplImage* cvCreateImage( CvSize size, int depth, int channels ); • 만들 빈 이미지의 크기, 허용 색상수를 설정하여 생성 • 컬러수: color depth: IPL_DEPTH_8U (각 채널당 8bit) channels: 1,2,3,4 (1=grey, 3=color) • Example)IplImage * img; img = cvCreateImage(cvSize(200,100), 8,3); • cvSet(image, CvScalar) • 이미지를 주어진 색으로 가득 칠한다 • Example) cvSet(img, CV_RGB(255,255,255));

  24. So far what you’ve learned: • IplImage • cvLoadImage (file_name) • cvCreateImage (size, depth, channels) • cvSaveImage (file_name, image) • cvReleaseImage (image) • cvNamedWindow (window_name) • cvShowImage (window_name, image) • cvDestroyWindow (window_name) • cvWaitKey (delay) • cvGet2D (image, y, x) • cvSet2D (image, y, x, cvScalar)

  25. Put everything together! HelloCV2.cpp int main() { IplImage * img; img = cvLoadImage(“c:\\test.jpg"); cvNamedWindow("HelloCV"); cvShowImage("HelloCV", img); cvWaitKey(); int x,y; for(x=0; x<100; x++) for(y=0; y<100; y++) { CvScalar s = cvGet2D(img, y,x); s.val[0] +=50; s.val[1] +=50; s.val[2] +=50; cvSet2D(img,y,x,s); } cvShowImage("HelloCV", img); cvWaitKey(); cvDestroyWindow("HelloCV"); cvReleaseImage(&img); return 0; }

  26. Coding Practice: Line Drawing • Make your own function for Horizontal line drawing: • 예) void DrawHLine (IplImage * img, int y, int st, int ed, CvScalar color) image

  27. Do more! (x,y) w h • Design a function that draws a rectangle • 예) void DrawRectangle(IplImage * img, int x, int y, int w, int h, CvScalar color) • Don’t forget to make sure a pixel is inside the image • 0 <= max_x <= img->width • 0 <= max_y <= img->height • If done, try to draw 50 random boxes with random colors!

  28. Do more2! • Make your own function for drawing any kind of line : • 예) void DrawLine (IplImage * img, int stx, int sty, int edx, int edy, CvScalar color) image

  29. For those who want more • OpenCV Official page: http://opencvlibrary.sourceforge.net • OpenCV WiKi pape: http://opencv.willowgarage.com/wiki/ • A Korean Community: http://www.opencv.co.kr/

More Related