티스토리 뷰

OpenCV

OpenCV - Canny Edge 함수(C++)

donie 2021. 1. 19. 00:56

1. 소스코드

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

static Mat input_img, edge_img;
static char *win_name = "Canny";
static int lowTh, highTh;

void CannyThr(int, void*){
	Canny(input_img, edge_img, lowTh, highTh, 3);
	imshow(win_name, edge_img);
}

void Canny_test_thresholds(char *name){
	input_img = imread(name, 0);
	edge_img.create(input_img.size(), input_img.type());
	namedWindow(win_name, CV_WINDOW_AUTOSIZE);
	createTrackbar("Threshold 1", win_name, &lowTh, 200, CannyThr);
	createTrackbar("Threshold 2", win_name, &highTh, 255, CannyThr);
	waitKey(0);
}

int main()
{
	Canny_test_thresholds("lena.jpg");
	return 0;
}

 

2. 컴파일

g++ -o canny canny.cpp `pkg-config opencv-3.3.1-dev --cflags --libs`

warning이 발생했지만, 잘 동작한다.

 

3. 실행

./canny

 

4. 결과

high threshold값에 따른 변화
000 ~ 255 000 ~ 128
낮은 threshold값은 0으로 동일하게 설정하고, 높은 threshold값을 다르게 설정하였다.
high threshold값이 높을 수록 더 깔끔한 결과가 얻어진다.
강한 edge의 기준이 더 높기 때문에 더 확실한 선만이 edge로 추출되는 것이다.

 

low threshold값에 따른 변화
0 ~ 255 128 ~ 255
이번에는 높은 threshold값을 255로 동일하게 설정하고, 낮은 threshold값을 다르게 설정하였다.
low threshold값이 높을 수록 더 깔끔한 결과가 얻어진다.
약한 edge의 기준이 더 높기 때문에 더 확실한 선만이 edge로 추출되는 것이다.

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함