forked from CihanTopal/ED_Lib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_it.cpp
112 lines (83 loc) · 4.13 KB
/
test_it.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "EDLib.h"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
//***************************** ED Edge Segment Detection *****************************
//Detection of edge segments from an input image
int delay = 1;
CommandLineParser parser(argc, argv, "{ @input | | }");
string input = parser.get<string>("@input");
Mat testImg = imread(input, IMREAD_GRAYSCALE);
imshow("Source Image", testImg);
//Call ED constructor
ED testED = ED(testImg, SOBEL_OPERATOR, 36, 8, 1, 10, 1.0, true); // apply ED algorithm
//Show resulting edge image
Mat edgeImg = testED.getEdgeImage();
imshow("Edge Image - PRESS ANY KEY TO CONTINUE", edgeImg);
waitKey(delay);
//Output number of segments
int noSegments = testED.getSegmentNo();
std::cout << "Number of edge segments: " << noSegments << std::endl;
//Get edges in segment form (getSortedSegments() gives segments sorted w.r.t. legnths)
std::vector< std::vector<Point> > segments = testED.getSegments();
//***************************** EDLINES Line Segment Detection *****************************
//Detection of line segments from the same image
EDLines testEDLines = EDLines(testImg);
Mat lineImg = testEDLines.getLineImage(); //draws on an empty image
imshow("Line Image 1 - PRESS ANY KEY TO CONTINUE", lineImg);
//Detection of lines segments from edge segments instead of input image
//Therefore, redundant detection of edge segmens can be avoided
testEDLines = EDLines(testED);
lineImg = testEDLines.drawOnImage(); //draws on the input image
imshow("Line Image 2 - PRESS ANY KEY TO CONTINUE", lineImg);
//Acquiring line information, i.e. start & end points
vector<LS> lines = testEDLines.getLines();
int noLines = testEDLines.getLinesNo();
std::cout << "Number of line segments: " << noLines << std::endl;
waitKey(delay);
//************************** EDPF Parameter-free Edge Segment Detection **************************
// Detection of edge segments with parameter free ED (EDPF)
EDPF testEDPF = EDPF(testImg);
Mat edgePFImage = testEDPF.getEdgeImage();
imshow("Edge Image Parameter Free", edgePFImage);
cout << "Number of edge segments found by EDPF: " << testEDPF.getSegmentNo() << endl;
waitKey(delay);
//***************************** EDCIRCLES Circle Segment Detection *****************************
//Detection of circles directly from the input image
EDCircles testEDCircles = EDCircles(testImg);
Mat circleImg = testEDCircles.drawResult(false, ImageStyle::CIRCLES);
imshow("Circle Image 1", circleImg);
//Detection of circles from already available EDPF or ED image
testEDCircles = EDCircles(testEDPF);
//Get circle information as [cx, cy, r]
vector<mCircle> circles = testEDCircles.getCircles();
//Get ellipse information as [cx, cy, a, b, theta]
vector<mEllipse> ellipses = testEDCircles.getEllipses();
//Circles and ellipses will be indicated in green and red, resp.
circleImg = testEDCircles.drawResult(true, ImageStyle::BOTH);
imwrite("CIRCLES_AND_ELLIPSES_RESULT_IMAGE.jpg", circleImg);
int noCircles = testEDCircles.getCirclesNo();
std::cout << "Number of circles: " << noCircles << std::endl;
waitKey(delay);
//*********************** EDCOLOR Edge Segment Detection from Color Images **********************
Mat colorImg = imread(input);
EDColor testEDColor = EDColor(colorImg, 36, 4, 1.5, true); //last parameter for validation
imshow("Color Edge Image - PRESS ANY KEY TO QUIT", testEDColor.getEdgeImage());
cout << "Number of edge segments detected by EDColor: " << testEDColor.getSegmentNo() << endl;
waitKey(delay);
// get lines from color image
EDLines colorLine = EDLines(testEDColor);
imshow("Color Line", colorLine.getLineImage());
std::cout << "Number of line segments: " << colorLine.getLinesNo() << std::endl;
waitKey(delay);
// get circles from color image
EDCircles colorCircle = EDCircles(testEDColor);
// TO DO :: drawResult doesnt overlay (onImage = true) when input is from EDColor
circleImg = colorCircle.drawResult(false, ImageStyle::BOTH);
imshow("Color Circle", circleImg);
std::cout << "Number of circles: " << colorCircle.getCirclesNo() << std::endl;
waitKey(delay);
return 0;
}