-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path28_1_Canny_edge_detection_with_Function.cpp
67 lines (51 loc) · 1.83 KB
/
28_1_Canny_edge_detection_with_Function.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
using namespace std;
using namespace cv;
Mat orgimg, gryimg;
int a = 0;
int b = 0;
int trackValue = 0;
void track(int, void*)
{
Mat cannyimg1(orgimg.rows, orgimg.cols, CV_8UC1, Scalar(0)); // kenarin kolon kiyaslamasi icin
Mat cannyimg2(orgimg.rows, orgimg.cols, CV_8UC1, Scalar(0)); // kenarin satir kiyaslamasi icin
// yukaridan asagi ya da asagidan yukarisi icin pixel farklarini threshold ile kiyasla
for (int i=0;i < orgimg.cols - 1 ; i++)
{
for (int j=0; j< orgimg.rows - 1 ; j++)
{
a = gryimg.at<uchar>(j + 1, i) - gryimg.at<uchar>(j, i); // 1,0 noktasindan 0,0 noktasini
b = gryimg.at<uchar>(j, i) - gryimg.at<uchar>(j + 1, i); // 0,0 noktasindan 1,0 noktasini
if (a > trackValue || b > trackValue) // pixel noktalari arasindaki fark esik degerinden buyukse
cannyimg1.at<uchar>(j, i) = 255; // white
else
cannyimg1.at<uchar>(j, i) = 0; // black
}
}
// sagdan sola ya da soldan saga pixel farklarini threshold ile kiyasla
for (int i =0 ; i< orgimg.cols -1; i++)
{
for (int j=0; j< orgimg.rows -1; j++)
{
a = gryimg.at<uchar>(j, i + 1) - gryimg.at<uchar>(j, i); // 0,1 noktasindan 0,0 noktasini
b = gryimg.at<uchar>(j, i) - gryimg.at<uchar>(j, i + 1); // 0,0 noktasindan 0,1 noktasini
if (a > trackValue || b > trackValue)
cannyimg2.at<uchar>(j, i) = 255;
else cannyimg2.at<uchar>(j, i) = 0;
}
}
imshow("original image", orgimg);
imshow("Canny Filter image", cannyimg1 + cannyimg2); // kolon ve satir kenar matrislerini birlestir
}
int main()
{
orgimg = imread("image.jpg");
cvtColor(orgimg, gryimg, COLOR_BGR2GRAY);
namedWindow("Trackbar", WINDOW_AUTOSIZE);
createTrackbar("Threshold", "Trackbar", &trackValue, 100, track);
waitKey(0);
return 0;
}