-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.cc
37 lines (32 loc) · 809 Bytes
/
image.cc
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
#include "image.h"
static void
trunc_colors(cv::Mat &m, int ncolors)
{
assert(m.type() == CV_8UC1);
uchar n = 256 / ncolors;
cv::Size size = m.size();
if (m.isContinuous()) {
size.width *= size.height;
size.height = 1;
}
for (int i = 0; i < size.height; ++i) {
uchar *p = m.ptr(i);
for (int j = 0; j < size.width; ++j) {
p[j] = (p[j] / n) * n;
}
}
}
void
get_sorted_objects_from_image(const cv::Mat &img,
std::vector<Obj> &objs,
const std::vector<double> ¶ms)
{
cv::Mat final, gray, pyrd, pyru;
cv::pyrDown(img, pyrd);
cv::pyrUp(pyrd, pyru);
cv::cvtColor(pyru, gray, CV_BGR2GRAY);
cv::equalizeHist(gray, final);
trunc_colors(final, params[0]);
objfind(final, objs);
sortobjs(objs);
}