-
Notifications
You must be signed in to change notification settings - Fork 6
/
boxes.cpp
58 lines (47 loc) · 1.41 KB
/
boxes.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
#include <cmath>
#include <algorithm>
#include "box.h"
#include "math.h"
#include "boxes.h"
#include "options.h"
// Find all the boxes in the image
std::vector<Coord> findBoxes(Pixels& img, const Blobs& blobs, Data& data)
{
typedef std::vector<Coord>::size_type size_type;
std::vector<Box> boxes;
std::vector<Coord> coords;
for (const CoordPair& pair : blobs)
{
// This may be the height, width, or diagonal
double dist = distance(pair.first, pair.last);
// Get rid of most the really big or really small objects
if (dist > MIN_HEIGHT && dist < MAX_DIAG)
{
Box box(img, blobs, pair.first);
if (box.valid())
boxes.push_back(box);
}
}
bool found = false;
size_type jump = 0;
// Now find the first box after the jump
for (size_type i = 1; i < boxes.size(); ++i)
{
// Ignore everything up to this big jump
if (!found && boxes[i].midpoint().y - boxes[i-1].midpoint().y > HUGE_JUMP)
{
jump = i;
found = true;
}
// We'll return the midpoints to use later
if (found)
coords.push_back(boxes[i].midpoint());
}
// Save this information for the first box after the jump
if (boxes.size() > 0)
{
data.width = boxes[jump].width();
data.diag = boxes[jump].diagonal();
}
return coords;
}