함수
/** @brief Finds edges in an image using the Canny algorithm @cite Canny86 .
The function finds edges in the input image and marks them in the output map edges using the
Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The
largest value is used to find initial segments of strong edges. See
<http://en.wikipedia.org/wiki/Canny_edge_detector>
@param image 8-bit input image.
@param edges output edge map; single channels 8-bit image, which has the same size as image .
@param threshold1 first threshold for the hysteresis procedure.
@param threshold2 second threshold for the hysteresis procedure.
@param apertureSize aperture size for the Sobel operator.
@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm
\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude (
L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough (
L2gradient=false ).
*/
CV_EXPORTS_W void Canny( InputArray image, OutputArray edges,
double threshold1, double threshold2,
int apertureSize = 3, bool L2gradient = false );
변수 설명
1. image: 8비트 입력 이미지입니다. 엣지를 검출할 원본 이미지입니다.
2. edges: 출력 엣지 맵입니다. 단일 채널 8비트 이미지로, 입력 이미지와 동일한 크기를 가집니다. 엣지가 검출된 결과가 이 이미지에 표시됩니다.
3. threshold1: 히스테리시스 절차를 위한 첫 번째 임계값입니다. 이 값과 threshold2 중 작은 값이 엣지 연결에 사용됩니다.
4. threshold2: 히스테리시스 절차를 위한 두 번째 임계값입니다. 이 값과 threshold1 중 큰 값이 강한 엣지의 초기 세그먼트를 찾는 데 사용됩니다.
5. apertureSize: Sobel 연산자를 위한 커널 크기입니다. 기본값은 3입니다. 일반적으로 3, 5, 7 등의 홀수 값을 사용합니다.
6. L2gradient**: 이미지 그라디언트 크기를 계산할 때 더 정확한 L2 노름을 사용할지 여부를 나타내는 플래그입니다. `true`로 설정하면 f = sqrt{(dI/dx)^2 + (dI/dy)^2} 을 사용하고, `false`로 설정하면 기본 f = |dI/dx|+|dI/dy| 을 사용합니다.
사용 예시
#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
// 이미지 읽기
cv::Mat image = cv::imread("image.jpg");
if (image.empty()) {
std::cerr << "이미지를 읽을 수 없습니다!" << std::endl;
return -1;
}
// 그레이스케일 변환
cv::Mat gray;
cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY);
// 가우시안 블러를 사용하여 노이즈 제거
cv::Mat blurred;
cv::GaussianBlur(gray, blurred, cv::Size(5, 5), 1.4);
// Canny 엣지 검출
cv::Mat edges;
cv::Canny(blurred, edges, 50, 150);
// 결과 이미지 출력
cv::imshow("Original Image", image);
cv::imshow("Canny Edges", edges);
cv::waitKey(0);
cv::destroyAllWindows();
return 0;
}
'영상처리' 카테고리의 다른 글
이미지 처리 분야의 주요 미해결 문제 (0) | 2024.12.15 |
---|---|
OpenCV C++ 사용 시 자주 하는 실수 1 (0) | 2024.12.14 |
OpenCV Install C++ (0) | 2024.12.14 |
OpenCV Install Python (0) | 2024.12.14 |
OpenCV resize C++ (0) | 2024.12.13 |