99 static cv::Mat itsLastFace(60, 60, CV_8UC2, 0x80aa) ;
100 static cv::Mat itsLastObject(60, 60, CV_8UC2, 0x80aa) ;
101 static std::string itsLastObjectCateg;
102 static bool doobject =
false;
108 inimg.
require(
"input", 320, 240, V4L2_PIX_FMT_YUYV);
110 itsProcessingTimer.
start();
111 int const roihw = 32;
118 outimg.
require(
"output", 640, 312, V4L2_PIX_FMT_YUYV);
134 int const smadj = smlev > 0 ? (1 << (smlev-1)) : 0;
135 int const dmx = (mx << smlev) + smadj;
136 int const dmy = (my << smlev) + smadj;
139 int const rx = std::min(
int(inimg.
width) - roihw, std::max(roihw, dmx));
140 int const ry = std::min(
int(inimg.
height) - roihw, std::max(roihw, dmy));
181 float kfxraw, kfyraw, kfximg, kfyimg;
182 itsKF->get(kfxraw, kfyraw, kfximg, kfyimg, inimg.
width, inimg.
height, 1.0F, 1.0F);
193 cv::Mat rawroi = rawimgcv(cv::Rect(rx - roihw, ry - roihw, roihw * 2, roihw * 2));
202 switch (objsz.depth_)
209 cv::cvtColor(rawroi, objroi, cv::COLOR_YUV2GRAY_YUYV);
212 size_t const elem = (objroi.cols * objroi.rows * 10) / 100;
213 std::vector<unsigned char> v; v.assign(objroi.datastart, objroi.dataend);
214 std::nth_element(v.begin(), v.begin() + elem, v.end());
215 unsigned char const thresh = std::min((
unsigned char)(100), std::max((
unsigned char)(30), v[elem]));
218 cv::threshold(objroi, objroi, thresh, 255, cv::THRESH_BINARY_INV);
221 cv::Mat pts; cv::findNonZero(objroi, pts);
222 cv::Rect r = cv::boundingRect(pts);
223 int const cx = r.x + r.width / 2;
224 int const cy = r.y + r.height / 2;
225 int const siz = std::min(roihw * 2, std::max(16, 8 + std::max(r.width, r.height)));
226 int const tlx = std::max(0, std::min(roihw*2 - siz, cx - siz/2));
227 int const tly = std::max(0, std::min(roihw*2 - siz, cy - siz/2));
228 cv::Rect ar(tlx, tly, siz, siz);
229 cv::resize(objroi(ar), objroi, cv::Size(objsz.width_, objsz.height_), 0, 0, cv::INTER_AREA);
235 cv::cvtColor(rawroi, objroi, cv::COLOR_YUV2RGB_YUYV);
236 cv::resize(objroi, objroi, cv::Size(objsz.width_, objsz.height_), 0, 0, cv::INTER_AREA);
240 LFATAL(
"Unsupported object detection input depth " << objsz.depth_);
247 std::ostringstream oss;
248 for (
size_t i = 0; i < scores.size(); ++i)
249 oss <<
itsObjectRecognition->category(i) <<
':' << std::fixed << std::setprecision(2) << scores[i] <<
' ';
253 float best1 = scores[0], best2 = scores[0];
size_t idx1 = 0, idx2 = 0;
254 for (
size_t i = 1; i < scores.size(); ++i)
256 if (scores[i] > best1) { best2 = best1; idx2 = idx1; best1 = scores[i]; idx1 = i; }
257 else if (scores[i] > best2) { best2 = scores[i]; idx2 = i; }
261 if (best1 > 90.0F && best2 < 20.0F)
265 itsLastObject = rawimgcv(cv::Rect(rx - 30, ry - 30, 60, 60)).clone();
267 LINFO(
"Object recognition: best: " << itsLastObjectCateg <<
" (" << best1 <<
276 cv::Mat grayroi; cv::cvtColor(rawroi, grayroi, cv::COLOR_YUV2GRAY_YUYV);
277 cv::equalizeHist(grayroi, grayroi);
280 std::vector<cv::Rect> faces; std::vector<std::vector<cv::Rect> > eyes;
286 LINFO(
"detected " << faces.size() <<
" faces");
288 itsLastFace = rawimgcv(cv::Rect(rx - 30, ry - 30, 60, 60)).clone();
291 for (
size_t i = 0; i < faces.size(); ++i)
294 cv::Rect
const & f = faces[i];
298 for (
auto const & e : eyes[i])
307 cv::Mat outimgcv(outimg.height, outimg.width, CV_8UC2, outimg.buf->data());
308 itsLastObject.copyTo(outimgcv(cv::Rect(520, 240, 60, 60)));
309 itsLastFace.copyTo(outimgcv(cv::Rect(580, 240, 60, 60)));
323 std::string
const & fpscpu = itsProcessingTimer.
stop();
330 doobject = ! doobject;