Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9557eb

Browse files
committed
formatted new files
1 parent deedd87 commit e9557eb

File tree

7 files changed

+466
-421
lines changed

7 files changed

+466
-421
lines changed

modules/imgproc/include/opencv2/imgproc/detail/legacy.hpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@
1010
namespace cv {
1111

1212
#ifdef __OPENCV_BUILD
13-
CV_EXPORTS void findContours_legacy( InputArray _image, OutputArrayOfArrays _contours,
14-
OutputArray _hierarchy, int mode, int method,
15-
Point offset = Point() );
16-
CV_EXPORTS void findContours_legacy( InputArray image, OutputArrayOfArrays contours,
17-
int mode, int method, Point offset = Point());
13+
CV_EXPORTS void findContours_legacy(InputArray _image,
14+
OutputArrayOfArrays _contours,
15+
OutputArray _hierarchy,
16+
int mode,
17+
int method,
18+
Point offset = Point());
19+
CV_EXPORTS void findContours_legacy(InputArray image,
20+
OutputArrayOfArrays contours,
21+
int mode,
22+
int method,
23+
Point offset = Point());
1824
#endif
1925

20-
} // cv::
26+
} // namespace cv
2127

2228
#endif // OPENCV_IMGPROC_DETAIL_LEGACY_HPP

modules/imgproc/src/contours_approx.cpp

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ struct ApproxItem
2020
int s; // 1-curvature
2121
bool removed;
2222
ApproxItem() : k(0), s(0), removed(false) {}
23-
ApproxItem(const Point &pt_, int s_) : pt(pt_), k(0), s(s_), removed(false) {}
23+
ApproxItem(const Point& pt_, int s_) : pt(pt_), k(0), s(s_), removed(false) {}
2424
};
2525

26-
static const schar abs_diff[16] = { 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1 };
26+
static const schar abs_diff[16] = {1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1};
2727
static const Point chainCodeDeltas[8] =
28-
{ {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1} };
28+
{{1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}};
2929

3030
// Pass 0.
3131
// Restores all the digital curve points from the chain code.
3232
// Removes the points (from the resultant polygon)
3333
// that have zero 1-curvature
34-
static vector<ApproxItem> pass_0(const vector<schar> & chain, Point pt, bool isApprox, bool isFull)
34+
static vector<ApproxItem> pass_0(const vector<schar>& chain, Point pt, bool isApprox, bool isFull)
3535
{
3636
vector<ApproxItem> res;
3737
const size_t len = chain.size();
@@ -52,11 +52,11 @@ static vector<ApproxItem> pass_0(const vector<schar> & chain, Point pt, bool isA
5252
return res;
5353
}
5454

55-
static vector<Point> gatherPoints(const vector<ApproxItem> & ares)
55+
static vector<Point> gatherPoints(const vector<ApproxItem>& ares)
5656
{
5757
vector<Point> res;
5858
res.reserve(ares.size() / 2);
59-
for (const ApproxItem & item : ares)
59+
for (const ApproxItem& item : ares)
6060
{
6161
if (item.removed)
6262
continue;
@@ -65,16 +65,16 @@ static vector<Point> gatherPoints(const vector<ApproxItem> & ares)
6565
return res;
6666
}
6767

68-
static size_t calc_support(const vector<ApproxItem> & ares, size_t i)
68+
static size_t calc_support(const vector<ApproxItem>& ares, size_t i)
6969
{
7070
const size_t len = ares.size();
7171
/* determine support region */
7272
int d_num = 0;
7373
int l = 0;
7474
size_t k = 1;
75-
for( ;; k++ )
75+
for (;; k++)
7676
{
77-
CV_Assert( k <= len );
77+
CV_Assert(k <= len);
7878
/* calc indices */
7979
const size_t i1 = (i >= k) ? (i - k) : (len - k + i);
8080
const size_t i2 = (i + k < len) ? (i + k) : (i + k - len);
@@ -86,12 +86,17 @@ static size_t calc_support(const vector<ApproxItem> & ares, size_t i)
8686
const int lk = dx * dx + dy * dy;
8787

8888
/* distance between p_i and the line (p_(i-k), p_(i+k)) */
89-
const int dk_num = (ares[i].pt.x - ares[i1].pt.x) * dy - (ares[i].pt.y - ares[i1].pt.y) * dx;
89+
const int dk_num =
90+
(ares[i].pt.x - ares[i1].pt.x) * dy - (ares[i].pt.y - ares[i1].pt.y) * dx;
9091

91-
union { int i; float f; } d;
92-
d.f = (float) (((double) d_num) * lk - ((double) dk_num) * l);
92+
union
93+
{
94+
int i;
95+
float f;
96+
} d;
97+
d.f = (float)(((double)d_num) * lk - ((double)dk_num) * l);
9398

94-
if( k > 1 && (l >= lk || ((d_num > 0 && d.i <= 0) || (d_num < 0 && d.i >= 0))))
99+
if (k > 1 && (l >= lk || ((d_num > 0 && d.i <= 0) || (d_num < 0 && d.i >= 0))))
95100
break;
96101

97102
d_num = dk_num;
@@ -100,14 +105,14 @@ static size_t calc_support(const vector<ApproxItem> & ares, size_t i)
100105
return k - 1;
101106
}
102107

103-
static int calc_cosine(const vector<ApproxItem> & ares, size_t i)
108+
static int calc_cosine(const vector<ApproxItem>& ares, size_t i)
104109
{
105110
const size_t k = ares[i].k;
106111
size_t j;
107112
int s;
108113
const size_t len = ares.size();
109114
/* calc k-cosine curvature */
110-
for( j = k, s = 0; j > 0; j-- )
115+
for (j = k, s = 0; j > 0; j--)
111116
{
112117
const size_t i1 = (i >= j) ? (i - j) : (len - j + i);
113118
const size_t i2 = (i + j < len) ? (i + j) : (i + j - len);
@@ -117,33 +122,36 @@ static int calc_cosine(const vector<ApproxItem> & ares, size_t i)
117122
const int dx2 = ares[i2].pt.x - ares[i].pt.x;
118123
const int dy2 = ares[i2].pt.y - ares[i].pt.y;
119124

120-
if( (dx1 | dy1) == 0 || (dx2 | dy2) == 0 )
125+
if ((dx1 | dy1) == 0 || (dx2 | dy2) == 0)
121126
break;
122127

123128
double temp_num = dx1 * dx2 + dy1 * dy2;
124-
temp_num =
125-
(float) (temp_num /
126-
sqrt( ((double)dx1 * dx1 + (double)dy1 * dy1) *
127-
((double)dx2 * dx2 + (double)dy2 * dy2) ));
128-
union { int i; float f; } sk;
129-
sk.f = (float) (temp_num + 1.1);
130-
131-
CV_Assert( 0 <= sk.f && sk.f <= 2.2 );
132-
if( j < k && sk.i <= s )
129+
temp_num = (float)(temp_num
130+
/ sqrt(((double)dx1 * dx1 + (double)dy1 * dy1)
131+
* ((double)dx2 * dx2 + (double)dy2 * dy2)));
132+
union
133+
{
134+
int i;
135+
float f;
136+
} sk;
137+
sk.f = (float)(temp_num + 1.1);
138+
139+
CV_Assert(0 <= sk.f && sk.f <= 2.2);
140+
if (j < k && sk.i <= s)
133141
break;
134142

135143
s = sk.i;
136144
}
137145
return s;
138146
}
139147

140-
static bool calc_nms_cleanup(const vector<ApproxItem> & ares, size_t i)
148+
static bool calc_nms_cleanup(const vector<ApproxItem>& ares, size_t i)
141149
{
142150
const size_t k2 = ares[i].k >> 1;
143151
const int s = ares[i].s;
144152
const size_t len = ares.size();
145153
size_t j;
146-
for( j = 1; j <= k2; j++ )
154+
for (j = 1; j <= k2; j++)
147155
{
148156
const size_t i1 = (i >= j) ? (i - j) : (len - j + i);
149157
const size_t i2 = (i + j < len) ? (i + j) : (i + j - len);
@@ -153,7 +161,7 @@ static bool calc_nms_cleanup(const vector<ApproxItem> & ares, size_t i)
153161
return j <= k2;
154162
}
155163

156-
static bool calc_dominance(const vector<ApproxItem> & ares, size_t i)
164+
static bool calc_dominance(const vector<ApproxItem>& ares, size_t i)
157165
{
158166
const size_t len = ares.size();
159167
CV_Assert(len > 0);
@@ -162,7 +170,7 @@ static bool calc_dominance(const vector<ApproxItem> & ares, size_t i)
162170
return ares[i].s <= ares[i1].s || ares[i].s <= ares[i2].s;
163171
}
164172

165-
inline size_t get_next_idx(const vector<ApproxItem> & ares, const size_t start)
173+
inline size_t get_next_idx(const vector<ApproxItem>& ares, const size_t start)
166174
{
167175
const size_t len = ares.size();
168176
size_t res = start + 1;
@@ -174,7 +182,7 @@ inline size_t get_next_idx(const vector<ApproxItem> & ares, const size_t start)
174182
return res;
175183
}
176184

177-
inline void clear_until(vector<ApproxItem> & ares, const size_t start, const size_t finish)
185+
inline void clear_until(vector<ApproxItem>& ares, const size_t start, const size_t finish)
178186
{
179187
const size_t len = ares.size();
180188
for (size_t i = start + 1; i < finish && i < len; ++i)
@@ -183,17 +191,17 @@ inline void clear_until(vector<ApproxItem> & ares, const size_t start, const siz
183191
}
184192
}
185193

186-
static bool calc_new_start(vector<ApproxItem> & ares, size_t & res)
194+
static bool calc_new_start(vector<ApproxItem>& ares, size_t& res)
187195
{
188196
const size_t len = ares.size();
189197
CV_Assert(len > 0);
190198
size_t i1;
191199
// remove all previous items from the beginning
192-
for( i1 = 1; i1 < len && ares[i1].s != 0; i1++ )
200+
for (i1 = 1; i1 < len && ares[i1].s != 0; i1++)
193201
{
194202
ares[i1 - 1].s = 0;
195203
}
196-
if( i1 == len )
204+
if (i1 == len)
197205
{
198206
// all points survived - skip to the end
199207
return false;
@@ -202,15 +210,15 @@ static bool calc_new_start(vector<ApproxItem> & ares, size_t & res)
202210

203211
size_t i2;
204212
// remove all following items from the end
205-
for( i2 = len - 2; i2 > 0 && ares[i2].s != 0; i2-- )
213+
for (i2 = len - 2; i2 > 0 && ares[i2].s != 0; i2--)
206214
{
207215
clear_until(ares, i2, len);
208216
ares[i2 + 1].s = 0;
209217
}
210218
i2++;
211219

212220
// only two points left
213-
if( i1 == 0 && i2 == len - 1 )
221+
if (i1 == 0 && i2 == len - 1)
214222
{
215223
// find first non-removed element from the start
216224
i1 = get_next_idx(ares, 0);
@@ -222,28 +230,28 @@ static bool calc_new_start(vector<ApproxItem> & ares, size_t & res)
222230
return true;
223231
}
224232

225-
static void pass_cleanup(vector<ApproxItem> & ares, size_t start_idx)
233+
static void pass_cleanup(vector<ApproxItem>& ares, size_t start_idx)
226234
{
227235
int count = 1;
228236

229237
const size_t len = ares.size();
230238
size_t first = start_idx;
231239
for (size_t i = start_idx, prev = i; i < len; ++i)
232240
{
233-
ApproxItem & item = ares[i];
241+
ApproxItem& item = ares[i];
234242
if (item.removed)
235243
continue;
236244
size_t next_idx = get_next_idx(ares, i);
237245
if (next_idx == len || next_idx - i != 1)
238246
{
239247
if (count >= 2)
240248
{
241-
if( count == 2 )
249+
if (count == 2)
242250
{
243251
const int s1 = ares[prev].s;
244252
const int s2 = ares[i].s;
245253

246-
if( s1 > s2 || (s1 == s2 && ares[prev].k <= ares[i].k) )
254+
if (s1 > s2 || (s1 == s2 && ares[prev].k <= ares[i].k))
247255
/* remove second */
248256
clear_until(ares, get_next_idx(ares, prev), get_next_idx(ares, i));
249257
else
@@ -268,15 +276,13 @@ static void pass_cleanup(vector<ApproxItem> & ares, size_t start_idx)
268276
}
269277
}
270278

271-
} // <anonymous>::
272-
273-
279+
} // namespace
274280

275-
vector<Point> cv::approximateChainTC89(vector<schar> chain, const Point &origin, const int method)
281+
vector<Point> cv::approximateChainTC89(vector<schar> chain, const Point& origin, const int method)
276282
{
277283
if (chain.size() == 0)
278284
{
279-
return vector<Point>({ origin });
285+
return vector<Point>({origin});
280286
}
281287

282288
const bool isApprox = method == CHAIN_APPROX_TC89_L1 || method == CHAIN_APPROX_TC89_KCOS;
@@ -292,7 +298,7 @@ vector<Point> cv::approximateChainTC89(vector<schar> chain, const Point &origin,
292298
// Determines support region for all the remained points */
293299
for (size_t i = 0; i < ares.size(); ++i)
294300
{
295-
ApproxItem & item = ares[i];
301+
ApproxItem& item = ares[i];
296302
if (item.removed)
297303
continue;
298304
item.k = calc_support(ares, i);
@@ -305,7 +311,7 @@ vector<Point> cv::approximateChainTC89(vector<schar> chain, const Point &origin,
305311
// Performs non-maxima suppression
306312
for (size_t i = 0; i < ares.size(); ++i)
307313
{
308-
ApproxItem & item = ares[i];
314+
ApproxItem& item = ares[i];
309315
if (calc_nms_cleanup(ares, i))
310316
{
311317
item.s = 0; // "clear"
@@ -317,7 +323,7 @@ vector<Point> cv::approximateChainTC89(vector<schar> chain, const Point &origin,
317323
// Removes non-dominant points with 1-length support region */
318324
for (size_t i = 0; i < ares.size(); ++i)
319325
{
320-
ApproxItem & item = ares[i];
326+
ApproxItem& item = ares[i];
321327
if (item.removed)
322328
continue;
323329
if (item.k == 1 && calc_dominance(ares, i))
@@ -327,7 +333,7 @@ vector<Point> cv::approximateChainTC89(vector<schar> chain, const Point &origin,
327333
}
328334
}
329335

330-
if( method == cv::CHAIN_APPROX_TC89_L1 )
336+
if (method == cv::CHAIN_APPROX_TC89_L1)
331337
{
332338
// Pass 4.
333339
// Cleans remained couples of points

modules/imgproc/src/contours_common.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
using namespace std;
1111
using namespace cv;
1212

13-
void cv::contourTreeToResults(CTree & tree, int res_type,
14-
OutputArrayOfArrays &_contours,
15-
OutputArray &_hierarchy)
13+
void cv::contourTreeToResults(CTree& tree,
14+
int res_type,
15+
OutputArrayOfArrays& _contours,
16+
OutputArray& _hierarchy)
1617
{
1718
// check if there are no results
18-
if (tree.isEmpty()
19-
|| (tree.elem(0).body.isEmpty() && (tree.elem(0).first_child == -1)))
19+
if (tree.isEmpty() || (tree.elem(0).body.isEmpty() && (tree.elem(0).first_child == -1)))
2020
{
2121
_contours.clear();
2222
return;
@@ -35,7 +35,7 @@ void cv::contourTreeToResults(CTree & tree, int res_type,
3535
CIterator it(tree);
3636
while (!it.isDone())
3737
{
38-
const CNode & elem = it.getNext_s();
38+
const CNode& elem = it.getNext_s();
3939
CV_Assert(elem.self() != -1);
4040
if (elem.self() == 0)
4141
continue;
@@ -61,14 +61,14 @@ void cv::contourTreeToResults(CTree & tree, int res_type,
6161
CIterator it(tree);
6262
while (!it.isDone())
6363
{
64-
const CNode & elem = it.getNext_s();
64+
const CNode& elem = it.getNext_s();
6565
if (elem.self() == 0)
6666
continue;
67-
Vec4i & h_vec = h_mat.at<Vec4i>(i);
67+
Vec4i& h_vec = h_mat.at<Vec4i>(i);
6868
h_vec = Vec4i(index_mapping.at(elem.next),
69-
index_mapping.at(elem.prev),
70-
index_mapping.at(elem.first_child),
71-
index_mapping.at(elem.parent));
69+
index_mapping.at(elem.prev),
70+
index_mapping.at(elem.first_child),
71+
index_mapping.at(elem.parent));
7272
++i;
7373
}
7474
}

0 commit comments

Comments
 (0)