21 #include <opencv2/core/core.hpp>
22 #include <opencv2/imgproc/imgproc.hpp>
188 int netw, neth, netc;
190 catch (std::logic_error
const & e) { inframe.done();
return; }
192 if (netw >
w || neth >
h)
193 LFATAL(
"Network wants " << netw <<
'x' << neth <<
" input, larger than camera " <<
w <<
'x' <<
h);
196 int const offx = ((
w - netw) / 2) & (~1);
197 int const offy = ((
h - neth) / 2) & (~1);
200 cv::Mat crop = cvimg(cv::Rect(offx, offy, netw, neth));
203 cv::cvtColor(crop,
itsCvImg, cv::COLOR_YUV2RGB_YUYV);
210 LINFO(
"Predicted in " << ptime <<
"ms");
230 inimg.
require(
"input",
w,
h, V4L2_PIX_FMT_YUYV);
235 outimg = outframe.get();
251 jevois::rawimage::drawFilledRect(outimg, w + 16, 0, outimg.width - w, h, jevois::yuyv::Black);
252 jevois::rawimage::writeText(outimg,
"Loading network -", w + 19, 3, jevois::yuyv::White);
253 jevois::rawimage::writeText(outimg,
"please wait...", w + 19, 15, jevois::yuyv::White);
262 if (
itsPredictFut.wait_for(std::chrono::milliseconds(5)) == std::future_status::ready)
266 bool success =
true;
float ptime = 0.0F;
270 paste_fut.get(); inframe.done();
278 itsRawInputCv.copyTo(outimgcv(cv::Rect(
w + 16, 0, cropw, croph)));
284 int y = croph + 3;
if (y +
int(
itsTensorFlow->top::get()) * 12 >
h - 21) y = 3;
289 w + 19, y, jevois::yuyv::White);
298 w + 19,
h - 11, jevois::yuyv::White);
310 paste_fut.get(); inframe.done();
319 if (outimg.
width < inimg.
width + 16)
LFATAL(
"USB output image must be larger than camera input");
320 int const cropw = outimg.
width - inimg.
width - 16;
321 int const croph = cropw;
324 if (cropw <= 0 || croph <= 0 || cropw >
w || croph >
h)
325 LFATAL(
"Network crop window must fit within camera frame");
328 int const offx = ((
w - cropw) / 2) & (~1);
329 int const offy = ((
h - croph) / 2) & (~1);
331 cv::Mat crop = cvimg(cv::Rect(offx, offy, cropw, croph));
334 cv::cvtColor(crop,
itsCvImg, cv::COLOR_YUV2RGB_YUYV);
345 int netinw, netinh, netinc;
itsTensorFlow->getInDims(netinw, netinh, netinc);
356 std::string
const & fpscpu = timer.
stop();