Skip to content

Commit 017bdaf

Browse files
Create edgeDetection.cpp
1 parent 7a24645 commit 017bdaf

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

edgeDetection.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
#include <opencv2/core.hpp>
5+
#include <opencv2/highgui.hpp>
6+
#include <opencv2/imgproc.hpp>
7+
8+
using namespace std;
9+
using namespace cv;
10+
11+
Mat img, gray, blurred, edge;
12+
13+
// Laplacian Operator Variables
14+
int kernel_size = 3;
15+
int ddepth = CV_16S;
16+
17+
// Canny Edge Detection Variables
18+
int lowerThreshold = 0;
19+
int max_lowThreshold = 100;
20+
21+
22+
void laplacianDetection() {
23+
24+
GaussianBlur(gray,
25+
blurred,
26+
cv::Size(3, 3), // smoothing window width and height in pixels
27+
3); // how much the image will be blurred
28+
29+
Laplacian(blurred,
30+
edge,
31+
ddepth, // Depth of the destination image
32+
kernel_size); // Size of the kernel
33+
34+
// converting back to CV_8U
35+
convertScaleAbs(edge, edge);
36+
}
37+
38+
39+
void CannyThreshold(int, void*) {
40+
41+
GaussianBlur(gray,
42+
blurred,
43+
cv::Size(3, 3), // smoothing window width and height in pixels
44+
3); // how much the image will be blurred
45+
46+
Canny(blurred,
47+
edge,
48+
lowerThreshold, // lower threshold
49+
50); // higher threshold
50+
51+
imshow("Edge Detection", edge);
52+
}
53+
54+
55+
56+
int main() {
57+
58+
img = imread("/Users/kemik/OneDrive/Skrivebord/lenna.png");
59+
60+
if (img.empty())
61+
{
62+
cout << "Could not open or find the image!" << endl;
63+
return -1;
64+
}
65+
66+
cvtColor(img, gray, COLOR_BGR2GRAY);
67+
68+
cv::namedWindow("Original", WINDOW_AUTOSIZE);
69+
cv::namedWindow("Gray", WINDOW_AUTOSIZE);
70+
cv::namedWindow("Blurred", WINDOW_AUTOSIZE);
71+
cv::namedWindow("Edge Detection", WINDOW_AUTOSIZE);
72+
73+
74+
// Canny Edge Detector
75+
createTrackbar("Min Threshold:", "Edge Detection", &lowerThreshold, max_lowThreshold, CannyThreshold);
76+
CannyThreshold(0,0);
77+
78+
// Laplacian Edge Detector
79+
//laplacianDetection();
80+
81+
imshow("Original", img);
82+
imshow("Gray", gray);
83+
imshow("Blurred", blurred);
84+
//imshow("Edge Detection", edge);
85+
86+
waitKey(0);
87+
88+
89+
90+
return 0;
91+
}

0 commit comments

Comments
 (0)