-
Notifications
You must be signed in to change notification settings - Fork 13
/
main_detection.cpp
94 lines (75 loc) · 3.29 KB
/
main_detection.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
/*----------------------------------------------------------------------------
This code is part of the following publication and was subject
to peer review:
"Multiscale line segment detector for robust and accurate SfM" by
Yohann Salaun, Renaud Marlet, and Pascal Monasse
ICPR 2016
Copyright (c) 2016 Yohann Salaun <yohann.salaun@imagine.enpc.fr>
This program is free software: you can redistribute it and/or modify
it under the terms of the Mozilla Public License as
published by the Mozilla Foundation, either version 2.0 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Mozilla Public License for more details.
You should have received a copy of the Mozilla Public License
along with this program. If not, see <https://www.mozilla.org/en-US/MPL/2.0/>.
----------------------------------------------------------------------------*/
#include "detection.hpp"
#include "interface.hpp"
#include "cmdLine/cmdLine.h"
using namespace std;
using namespace cv;
int main(int argc, char* argv[]){
// Seed random function
srand((unsigned int)(time(0)));
// parse arguments
CmdLine cmd;
string dirPath;
string picList;
bool consecutive = true;
bool withDetection = false;
double segment_length_threshold = 0;
bool multiscale = true;
// required
cmd.add( make_option('d', dirPath, "dirPath") );
cmd.add( make_option('i', picList, "inputPic") );
// optional
cmd.add( make_option('m', multiscale, "multiscale") );
cmd.add( make_option('t', segment_length_threshold, "threshold") );
try {
if (argc == 1) throw std::string("Invalid command line parameter.");
cmd.process(argc, argv);
} catch(const std::string& s) {
std::cerr << "Usage: " << argv[0] << '\n'
<< "[-d|--dirPath] feature path]\n"
<< "[-i|--inputPic] list of pictures] \n"
<< "\n[Optional]\n"
<< "[-m|--multiscale] multiscale option (default = TRUE)\n"
<< "[-t|--threshold] threshold for segment length (default = 0.05% of image size)\n"
<< endl;
return EXIT_FAILURE;
}
dirPath += "/";
vector<string> picName, picPath;
readPictureFile(picList, picName, picPath);
const string ext = (multiscale)? "" : "_no_mlsd";
const int nPictures = picName.size();
// compute descriptors and optionally detect lines
clock_t processing_time = clock();
for(int i = 0; i < nPictures; i++){
cout << "picture " << i << ": " << picName[i] << endl;
Mat im = imread(picPath[i], CV_LOAD_IMAGE_GRAYSCALE);
vector<Mat> imagePyramid = computeImagePyramid(im, multiscale);
vector<Segment> segments = lsd_multiscale(imagePyramid, segment_length_threshold, multiscale);
saveLines(segments, dirPath, picName[i]+ext);
}
cout << "PROCESSED IN " << (clock() - processing_time) / float(CLOCKS_PER_SEC) << endl;
for(int i = 0; i < nPictures; i++){
Mat im = imread(picPath[i], CV_LOAD_IMAGE_COLOR);
vector<Segment> segments = readLines(dirPath, picName[i]+ext);
saveLinesPicture(segments, im, dirPath, picName[i]+ext, false);
}
return 0;
}