Programming/Image Processing

[OpenCV] Edge detection(Sobel Filter) 사용하기 예제

DevMonster 2014. 1. 10. 01:36
반응형

[원본 이미지]

[Sobel Filter를 이용하여 에지검출 Source code(C++)]

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
#include <opencv\cv.h>
#include <opencv\highgui.h>
 
using namespace cv;
using namespace std;
 
int main(void)
{
    // Original Image
    Mat image =    imread("circuit/c.jpg", CV_LOAD_IMAGE_COLOR);
    imshow("Original image", image);
 
    // Original Image to Gray Image
    Mat gray;
    cvtColor(image, gray, CV_BGR2GRAY);
 
    // Sobel Filter
    Mat sobel;
    Mat sobelX;
    Mat sobelY;
    Sobel(gray, sobelX, CV_8U, 1, 0);
    Sobel(gray, sobelY, CV_8U, 0, 1);
    sobel = abs(sobelX) + abs(sobelY);
 
    // Result Image
    imshow("image", sobel);
 
    waitKey(0);                                        
    return 0;
}


[결과 이미지]


728x90
반응형