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();
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;
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();
JEVOIS_REGISTER_MODULE(ArUcoBlob)
Identify objects using TensorFlow deep neural network.
virtual ~TensorFlowSingle()
Virtual destructor for safe inheritance.
virtual void process(jevois::InputFrame &&inframe) override
Processing function, no video output.
std::future< float > itsPredictFut
virtual void postUninit() override
Un-initialization.
cv::Mat itsRawPrevOutputCv
std::shared_ptr< TensorFlow > itsTensorFlow
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function with video output to USB.
std::vector< jevois::ObjReco > itsResults
TensorFlowSingle(std::string const &instance)
Constructor.
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
void sendSerialObjReco(std::vector< ObjReco > const &res)
StdModule(std::string const &instance)
std::string const & stop(double *seconds)
void paste(RawImage const &src, RawImage &dest, int dx, int dy)
cv::Mat cvImage(RawImage const &src)
void writeText(RawImage &img, std::string const &txt, int x, int y, unsigned int col, Font font=Font6x10)
void drawFilledRect(RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int col)
cv::Mat rescaleCv(cv::Mat const &img, cv::Size const &newdims)
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async(Function &&f, Args &&... args)
std::string sformat(char const *fmt,...) __attribute__((format(__printf__
unsigned short constexpr Black
unsigned short constexpr White
unsigned short constexpr MedGrey