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);
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();
292 itsRawInputCv.copyTo(outimgcv(cv::Rect(w, 0, dispw, disph)));
297 int y = disph + 3;
if (y +
itsDarknet->top::get() * 12 >
h - 21) y = 3;
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();
JEVOIS_REGISTER_MODULE(ArUcoBlob)
Detect salient objects and identify them using Darknet deep neural network.
JEVOIS_DECLARE_PARAMETER(netin, cv::Size, "Width and height (in pixels) of the neural network input " "layer. This is the size to which the image crop taken around the most salient " "location in each frame will be rescaled before feeding to the neural network.", cv::Size(128, 128), ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(foa, cv::Size, "Width and height (in pixels) of the focus of attention. " "This is the size of the image crop that is taken around the most salient " "location in each frame. The foa size must fit within the camera input frame size.", cv::Size(128, 128), ParamCateg)
Parameter.
DarknetSaliency(std::string const &instance)
Constructor.
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function with video output to USB.
std::shared_ptr< Darknet > itsDarknet
virtual void getSalROI(jevois::RawImage const &inimg, int &rx, int &ry, int &rw, int &rh)
Helper function: compute saliency ROI in a thread, return top-left corner and size.
std::shared_ptr< Saliency > itsSaliency
virtual void postUninit() override
Un-initialization.
std::future< float > itsPredictFut
cv::Mat itsRawPrevOutputCv
virtual void process(jevois::InputFrame &&inframe) override
Processing function, no video output.
virtual ~DarknetSaliency()
Virtual destructor for safe inheritance.
std::vector< jevois::ObjReco > itsResults
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
void sendSerialObjDetImg2D(unsigned int camw, unsigned int camh, float x, float y, float w, float h, std::vector< ObjReco > const &res)
StdModule(std::string const &instance)
std::string const & stop(double *seconds)
ENV_INTG32_TYPE intg32
32-bit signed integer
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)
void convertCvRGBtoCvYUYV(cv::Mat const &src, cv::Mat &dst)
void drawRect(RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int thick, 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 LightPink
unsigned short constexpr White