-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_borders.cpp
More file actions
26 lines (23 loc) · 773 Bytes
/
find_borders.cpp
File metadata and controls
26 lines (23 loc) · 773 Bytes
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
#include "find_borders.h"
#include "debug.h"
using namespace cv;
Rect find_borders(const Mat &image)
{
Mat work = image.clone();
vector<vector<Point> > contours;
findContours(work, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
// Sort the contours in decreasing area
sort(contours.begin(), contours.end(), [](const vector<Point>& c1, const vector<Point>& c2) {
return contourArea(c1, false) > contourArea(c2, false);
});
if (contours.size() > 0) {
Rect r = boundingRect(contours[0]);
#if 0 || defined(DISPLAY_INTERMEDIATE_IMAGES)
Mat work = image.clone();
rectangle(work, r, Scalar(0, 0, 255));
display_image("Borders", work);
#endif /* DISPLAY_INTERMEDIATE_IMAGES */
return r;
}
return Rect();
}