-
Notifications
You must be signed in to change notification settings - Fork 1
/
edge.cpp
executable file
·67 lines (51 loc) · 1.41 KB
/
edge.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/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
using namespace cv;
using namespace std;
int edgeThresh = 1;
Mat image, gray, edge, cedge;
// define a trackbar callback
static void onTrackbar(int, void*)
{
blur(gray, edge, Size(3,3));
// Run the edge detector on grayscale
Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
cedge = Scalar::all(0);
image.copyTo(cedge, edge);
imshow("Edge map", cedge);
}
static void help()
{
printf("\nThis sample demonstrates Canny edge detection\n"
"Call:\n"
" /.edge [image_name -- Default is fruits.jpg]\n\n");
}
const char* keys =
{
"{1| |fruits.jpg|input image name}"
};
int main( int argc, const char** argv )
{
help();
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>("1");
image = imread(filename, 1);
if(image.empty())
{
printf("Cannot read image file: %s\n", filename.c_str());
help();
return -1;
}
cedge.create(image.size(), image.type());
cvtColor(image, gray, COLOR_BGR2GRAY);
// Create a window
namedWindow("Edge map", 1);
// create a toolbar
createTrackbar("Canny threshold", "Edge map", &edgeThresh, 100, onTrackbar);
// Show the image
onTrackbar(0, 0);
// Wait for a key stroke; the same function arranges events processing
waitKey(0);
return 0;
}