21#include <opencv2/core/core.hpp>
22#include <opencv2/imgproc/imgproc.hpp>
130 itsDarknet = addSubComponent<Darknet>(
"darknet");
157 int netw, neth, netc;
158 try {
itsDarknet->getInDims(netw, neth, netc); }
159 catch (std::logic_error
const & e) { inframe.done();
return; }
161 if (netw > w) netw = w;
162 if (neth >
h) neth =
h;
165 int const offx = ((w - netw) / 2) & (~1);
166 int const offy = ((
h - neth) / 2) & (~1);
169 cv::Mat crop = cvimg(cv::Rect(offx, offy, netw, neth));
172 cv::cvtColor(crop,
itsCvImg, cv::COLOR_YUV2RGB_YUYV);
179 LINFO(
"Predicted in " << ptime <<
"ms");
199 inimg.
require(
"input", w,
h, V4L2_PIX_FMT_YUYV);
204 outimg = outframe.get();
228 if (
itsPredictFut.wait_for(std::chrono::milliseconds(5)) == std::future_status::ready)
232 bool success =
true;
float ptime = 0.0F;
236 paste_fut.get(); inframe.done();
249 int y = neth + 3;
if (y +
int(
itsDarknet->top::get()) * 12 >
h - 21) y = 3;
275 paste_fut.get(); inframe.done();
284 if (outimg.
width < inimg.
width)
LFATAL(
"USB output image must be larger than camera input");
286 int const neth = netw;
289 if (netw > w || neth >
h)
LFATAL(
"Network input window must fit within camera frame");
292 int const offx = ((w - netw) / 2) & (~1);
293 int const offy = ((
h - neth) / 2) & (~1);
295 cv::Mat crop = cvimg(cv::Rect(offx, offy, netw, neth));
298 cv::cvtColor(crop,
itsCvImg, cv::COLOR_YUV2RGB_YUYV);
309 int netinw, netinh, netinc;
itsDarknet->getInDims(netinw, netinh, netinc);
316 std::string
const & fpscpu = timer.
stop();
JEVOIS_REGISTER_MODULE(ArUcoBlob)
Identify objects using Darknet deep neural network.
cv::Mat itsRawPrevOutputCv
std::shared_ptr< Darknet > itsDarknet
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function with video output to USB.
DarknetSingle(std::string const &instance)
Constructor.
std::future< float > itsPredictFut
virtual void postUninit() override
Un-initialization.
std::vector< jevois::ObjReco > itsResults
virtual ~DarknetSingle()
Virtual destructor for safe inheritance.
virtual void process(jevois::InputFrame &&inframe) override
Processing function, no video output.
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)
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