페이지

2012년 12월 23일 일요일

캐니 엣지(Canny Edge)

캐니 엣지는 영상처리에서 폭넓게 사용되는 특징 추출 방법중의 하나로, 영상에서 물체의 경계를 찾기 위한 알고리즘입니다.

장점
  1. 명확하게 하나의 선으로 엣지를 찾을 수 있다.
  2. 상, 하한 임계값 설정을 통하여 다양한 환경에 적용할 수 있다.

입력
  1. 입력 영상
  2. 소벨 커널의 크기
  3. 상/하한 임계값

절차
  1. 소벨 엣지(Sobel Edge)를 통하여 엣지의 방향과 크기를 구함.
  2. Non-Maximum Suppression
    엣지의 방향에서 가장 강한 엣지를 선택.
  3. Hysteresis Thresholding
    높은 임계값을 이용하여 엣지를 선택하고, 엣지라면 이후에는 낮은 임계값을 이용하여 계속해서 엣지를 탐색해 나감.
code
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace cv;

int main(){
 Mat src, src_gray;
 Mat detected_edges;

 int lowThreshold = 50;
 int ratio = 3;
 int kernel_size = 3;

 /// Read an image
 src = imread("lena.png");
 if( !src.data )
 { return -1; }
 

 /// Convert the image to grayscale
 cvtColor( src, src_gray, CV_BGR2GRAY );

 /// Reduce noise with a kernel 3x3
 blur( src_gray, detected_edges, Size(3,3) );

 /// Canny detector
 Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size ); 

 /// Show result
 imshow( "source", src );
 imshow( "canny edge", detected_edges );

 /// Wait until user exit program by pressing a key
 waitKey(0);

}


결과


링크

댓글 없음:

댓글 쓰기