21 #include <opencv2/core/core.hpp>
22 #include <opencv2/imgproc/imgproc.hpp>
32 "This is the size of the image crop that is taken around the most salient "
33 "location in each frame. The foa size must fit within the camera input frame size.",
34 cv::Size(128, 128), ParamCateg);
38 "layer. This is the size to which the image crop taken around the most salient "
39 "location in each frame will be rescaled before feeding to the neural network.",
40 cv::Size(128, 128), ParamCateg);
127 public jevois::Parameter<foa, netin>
135 itsSaliency = addSubComponent<Saliency>(
"saliency");
136 itsDarknet = addSubComponent<Darknet>(
"darknet");
169 int const smfac = (1 << smlev);
175 cv::Size roisiz = foa::get(); rw = roisiz.width; rh = roisiz.height;
176 rw = std::min(rw,
w); rh = std::min(rh,
h); rw &= ~1; rh &= ~1;
177 unsigned int const dmx = (mx << smlev) + (smfac >> 2);
178 unsigned int const dmy = (my << smlev) + (smfac >> 2);
179 rx =
int(dmx + 1 + smfac / 4) - rw / 2;
180 ry =
int(dmy + 1 + smfac / 4) - rh / 2;
181 rx = std::max(0, std::min(rx,
w - rw));
182 ry = std::max(0, std::min(ry,
h - rh));
201 cv::Mat rawroi = rawimgcv(cv::Rect(rx, ry, rw, rh));
205 cv::cvtColor(rawroi, rgbroi, cv::COLOR_YUV2RGB_YUYV);
214 int netinw, netinh, netinc;
itsDarknet->getInDims(netinw, netinh, netinc);
221 LINFO(
"Predicted in " << ptime <<
"ms");
226 catch (std::logic_error
const & e) { }
243 inimg.
require(
"input",
w,
h, V4L2_PIX_FMT_YUYV);
252 outimg = outframe.get();
253 outimg.require(
"output", outimg.width, outimg.height, V4L2_PIX_FMT_YUYV);
265 jevois::rawimage::drawFilledRect(outimg, w, 0, outimg.width - w, h, jevois::yuyv::Black);
266 jevois::rawimage::writeText(outimg,
"Loading network -", w + 3, 3, jevois::yuyv::White);
267 jevois::rawimage::writeText(outimg,
"please wait...", w + 3, 15, jevois::yuyv::White);
276 if (
itsPredictFut.wait_for(std::chrono::milliseconds(5)) == std::future_status::ready)
280 bool success =
true;
float ptime = 0.0F;
284 paste_fut.get(); inframe.done();
297 int y = disph + 3;
if (y +
itsDarknet->top::get() * 12 >
h - 21) y = 3;
302 w + 3, y, jevois::yuyv::White);
312 w + 3,
h - 11, jevois::yuyv::White);
323 paste_fut.get(); sal_fut.get(); inframe.done();
329 paste_fut.get(); sal_fut.get();
333 cv::Mat rawroi = rawimgcv(cv::Rect(rx, ry, rw, rh));
337 cv::cvtColor(rawroi, rgbroi, cv::COLOR_YUV2RGB_YUYV);
346 float fac =
float(outimg.width -
w) /
float(rgbroi.cols);
347 cv::Size displaysize(outimg.width -
w,
int(rgbroi.rows * fac + 0.4999F));
357 int netinw, netinh, netinc;
itsDarknet->getInDims(netinw, netinh, netinc);
364 std::string
const & fpscpu = timer.
stop();