1 / 24

Multimedia Programming 04: 점 , 선 , 면

Multimedia Programming 04: 점 , 선 , 면. Departments of Digital Contents Sang Il Park. Outline. Review OpenCV 익숙해 지기 선 면 Point Processing 1. Review. Pixel and color CvScalar cvGet2D cvSet2D. Pixel 의 값 = ( 위치 , 색 ). 위치 : 각 픽셀의 2D 좌표 (Image Coordinate System)

Download Presentation

Multimedia Programming 04: 점 , 선 , 면

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 04:점, 선, 면 Departments of Digital Contents Sang Il Park

  2. Outline • Review • OpenCV 익숙해 지기 • 선 • 면 • Point Processing 1

  3. Review • Pixel and color • CvScalar • cvGet2D • cvSet2D

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

  5. 색을 저장하는 변수: 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]; };

  6. 이미지에서 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를 정보를 참조할것)

  7. 빈 이미지 생성하기 • 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));

  8. 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; }

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

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

  11. 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)

  12. 집에서 풀어 볼 것! (작년 기출문제) • 원본 이미지:(lena.png) • 원본 이미지:

  13. Program Assignment #1 • Long long times ago in Russian Empire • Sergei Mikhailovich Prokudin-Gorskii (1863-1944) • A man who pursuing a colorful future in 1907 http://www.loc.gov/exhibits/empire/

  14. Program Assignment #1 • His invention A camera His camera

  15. Program Assignment #1 • His pictures with the current digital technology

  16. Program Assignment #1 • Recover the colorful world in 1907 by yourself! 1I3 B align 1I3 G 1I3 R

  17. Program Assignment #1 • 홈페이지에 4개의 예제 그림이 있음: • http://dasan.sejong.ac.kr/~sipark/class2010/mm/ • 숙제 기한: Sep.17 PM 23:59 (금요일) • Email 제출 : sipark@sejong.ac.kr • Report ( doc, hwp, pdf) • Source code (cpp 파일) • 복수개의 파일(h 파일 포함)이 필요 하다면 첨부할 것 • 점수: • 주석 및 리포트: 20 • Color 이미지가 나온다: 40 • 자동으로 그림이 맞추어 진다: 40

  18. 선, 면

  19. 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

  20. Coding Practice: Line Drawing2 • Make your own function for Vertical line drawing: • 예) void DrawVLine (IplImage * img, int x, int st, int ed, CvScalar color) image

  21. Coding Practice: Line Drawing 3 • 시작점과 끝점을 잇는 라인?: • 예) void DrawLine(IplImage * img, int x1, int y1, int x2, int y2, CvScalar color)

  22. Coding Practice: Line Drawing 3 • 시작점과 끝점을 잇는 라인?: • 예) void DrawLine(IplImage * img, int x1, int y1, int x2, int y2, CvScalar color)

  23. 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!

  24. For those who want more • OpenCV Wiki-pages: http://opencvlibrary.sourceforge.net • For OpenCV Reference Manual: • http://opencv.willowgarage.com/documentation/index.html • Supplied documentation: • OpenCV/docs/index.htm, faq.htm • A Korean Community: http://www.opencv.co.kr/

More Related