[OpenCV] FAST 코너 검출

이번 글에서는 FAST 코너 검출에 대해 알아보겠습니다.

이전 글에서 배운 해리스 코너 검출 이후로 몇몇 코너 검출 방법이 생겨났습니다. 하지만 이러한 검출 방법은 연산 속도가 느리다는 단점이 있습니다. FAST 코너 검출은 이러한 코너 검출보다 빠른 장점이 있습니다.

방법

FAST 코너 검출은 점 p를 둘러싸고 있는 1번부터 16번까지의 픽셀의 밝기를 비교합니다.

점 p가 코너인지 아닌지를 판단하는 방법은 16개의 픽셀 중 9개 이상의 픽셀이 연속적으로 밝거나, 어두우면 코너로 정의합니다.

FAST 코너 검출 방법은 특정 점 주변 픽셀을 참고하기 때문에 노이즈가 많은 경우엔 검출이 잘 되지 않을 수 있습니다.

코드

OpenCV에서는 FAST 코너 검출 방법을 구현한 FAST 함수를 제공합니다.

/*
InputArray image 입력 영상
std::vector<KeyPoint>& keypoints 검출된 특징점(코너 점 좌표 저장 됨)
int threshold 중심 픽셀 값과 주변 픽셀값과의 차이 임계값
bool nonmaxSuppression=true 비최대 억제 수행 여부
*/
void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints, int threshold, bool nonmaxSuppression=true );

FAST 함수를 사용한 코드는 아래와 같습니다.

Mat src = imread("building.jpg", IMREAD_COLOR);
if (src.empty())
{
	cerr << "image open error" << endl;
	return -1;
}

Mat src_gray;
cvtColor(src, src_gray, COLOR_BGR2GRAY);
if (src_gray.empty())
{
	cerr << "image convert error" << endl;
	return -1;
}

vector<KeyPoint> keypoints;
FAST(src_gray, keypoints, 70, true);

Mat dst;
cvtColor(src_gray, dst, COLOR_GRAY2BGR);

for (KeyPoint point : keypoints)
{
	Point pt(cvRound(point.pt.x), cvRound(point.pt.y));
	circle(dst, pt, 5, Scalar(0,0,255), 2);
}

imshow("src", src);
imshow("dst", dst);

waitKey();
destroyAllWindows();

실행 결과는 아래와 같습니다.

이상으로 FAST 코너 검출에 대해 알아보았습니다.