-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
160 lines (81 loc) · 4.19 KB
/
main.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// The heartbeat-seamcarving programme serves to segment lines of a given text block by means of the heartbeat-seamcarve algorithm as published by Mathias Seuret, Daniel Stökl Ben Ezra, Marcus Liwicki. Robust Heartbeat-based Line Segmentation Methods for Regular Texts and Paratextual Elements. HIP 2017 - Proceedings of the 4th International Workshop on Historical Document Imaging and Processing, Nov 2017, Kyoto, Japan. 〈hal-01677054〉. https://hal.archives-ouvertes.fr/hal-01677054
// Copyright (C) 2017 Mathias Seuret, Daniel Stökl Ben Ezra, Marcus Liwicki. EPHE, PSL. U Fribourg.
// Contact at: daniel.stoekl@ephe.psl.eu, mathias.seuret@unifr.ch, marcus.liwicki@unifr.ch.
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License Version 3 as published by the Free Software Foundation.
// 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 GNU General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <https://www.gnu.org/licenses/lgpl-3.0.en.html>.
#include "include/seam_carving.h"
using namespace cv;
using namespace std;
int main(int argc, char * argv [])
{
//cv::namedWindow("for testing");
if(argc <6) {
std::cout << "Invalid number of arguments" << std::endl;
std::cout << "Arguments are: " << std::endl;
std::cout << "1- Entry Filename " << std::endl;
std::cout << "2- Output Filename " << std::endl;
std::cout << "3- Number of columns r (int)" << std::endl;
// division of the textblock into columns for the calculation of the separation lines.
std::cout << "4- Cubic smoothing term b (float)" << std::endl;
std::cout << "5- Gaussian sigma smoothing term (float) " << std::endl;
std::cout << "6- Optional Line Completion (int 0 or 1) " << std::endl;
// 1 with heartbeat, 0 without
std::cout << "7- Optional SeamCarving Optimization size (int 1 or bigger) " << std::endl;
// i.e. the number of pixels the seamcarve can climb or descend by 1 pixel width.
std::cout << "8- Optional csv output filename " << std::endl;
//cv::waitKey(0);
return 0;
}
std::cout << string(argv[1]) << std::endl;
cv::Mat img = cv::imread(string(argv[1]), 1);
if(img.rows<2) {
std::cout << "Filename does not exist" << std::endl;
//cv::waitKey(0);
return 0;
}
//Seam Carving parameters
std::string rs(argv[3]);
std::string bs(argv[4]);
std::string sigmas(argv[5]);
std::string text_file="";
std::string::size_type sz;
bool complete_lines = false;
int optim =1;
if(argc>=7) {
std::string comp(argv[6]);
int compi = int(std::stof(comp,&sz));
if(compi >=1) complete_lines = true;
}
if(argc>=8) {
std::string optim_size(argv[7]);
int optim_sizei = int(std::stof(optim_size,&sz));
if(optim_sizei >=1) optim = optim_sizei;
}
if(argc>=9) {
std::string file(argv[8]);
text_file=file;
}
bool hb = true;
if(argc>=10) {
hb = argv[9][0] != '0';
}
int r = int(std::stof(rs,&sz));
float b = std::stof(bs,&sz);
float sigma = std::stof(sigmas,&sz);
std::cout << "Computing seam carving with parameters: " << std::endl;
std::cout << "r " << r << std::endl;
std::cout << "b " << b << std::endl;
std::cout << "sigma " << sigma << std::endl;
std::cout << "heartbeat " << hb << std::endl;
Carve::SeamCarving seam(r,b,sigma,img,complete_lines, optim,text_file, hb);
seam.computeMedialSeam();
seam.drawMedialSeam(img);
seam.computeCarvedSeams();
seam.drawCarvedSeam(img);
seam.writeMatches();
cv::imwrite(string(argv[2]), img);
std::cout << "Seam Carving Done!!" << std::endl;
//cv::waitKey(0);
return 0;
}