장점
- 명확하게 하나의 선으로 엣지를 찾을 수 있다.
- 상, 하한 임계값 설정을 통하여 다양한 환경에 적용할 수 있다.
입력
- 입력 영상
- 소벨 커널의 크기
- 상/하한 임계값
절차
- 소벨 엣지(Sobel Edge)를 통하여 엣지의 방향과 크기를 구함.
- Non-Maximum Suppression
엣지의 방향에서 가장 강한 엣지를 선택. - 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);
}
링크

댓글 없음:
댓글 쓰기