23#include <opencv2/imgproc/imgproc.hpp>
33 using jevois::dnn::PostProcessorDetect::PostProcessorDetect;
64 jevois::dnn::pipeline::PostProc
const & val)
override
67 if (val == jevois::dnn::pipeline::PostProc::Detect)
131 itsPipeline = addSubComponent<MyPipeline>(
"pipeline");
152 std::shared_ptr<MyPostProc> mpp = std::dynamic_pointer_cast<MyPostProc>(
itsPipeline->getPostProcessor());
159 itsPipeline->process(inimg,
this, outimg, helper, idle);
170 itsPipeline->process(inimg,
this, outimg, helper, idle);
173 cv::Mat inhd = fut.get();
174 if (jevois::frameNum() % 30 == 0)
LINFO(
"Input frame is " << inhd.cols <<
'x' << inhd.rows);
177 std::vector<jevois::ObjDetect>
const & detections = mpp->getDetections();
178 if (jevois::frameNum() % 30 == 0)
LINFO(
"Got " << detections.size() <<
" detections");
196 cv::Rect r(d.tlx * inhd.cols / inimg.
width,
197 d.tly * inhd.rows / inimg.
height,
198 (d.brx - d.tlx) * inhd.cols / inimg.
width,
199 (d.bry - d.tly) * inhd.rows / inimg.
height);
200 cv::Mat roi = inhd(r);
204 if (roi.empty())
continue;
207 cv::Mat gray_roi; cv::cvtColor(roi, gray_roi, cv::COLOR_BGR2GRAY);
208 cv::Mat edges; cv::Canny(gray_roi, edges, 50, 100, 3);
209 cv::Mat chans[4] { edges, edges, edges, edges };
210 cv::Mat mask; cv::merge(chans, 4, mask);
223 std::string roi_name =
"roi" + std::to_string(i);
224 unsigned short rw = mask.cols, rh = mask.rows;
226 helper->
drawImage(roi_name.c_str(), mask,
true, r.x, r.y, rw, rh,
false ,
true );
230 helper->
drawCircle((d.tlx + d.brx)/2, (d.tly+d.bry)/2, std::min(d.brx - d.tlx, d.bry - d.tly)/2);
247 doprocess(inframe,
nullptr,
nullptr,
false);
271 doprocess(inframe, &outimg,
nullptr,
false);
287 std::string
const & fpscpu = timer.
stop();
291 unsigned short winw, winh;
296 int x = 0, y = 0;
unsigned short w = 0,
h = 0;
300 doprocess(inframe,
nullptr, &helper, idle);
303 helper.
iinfo(inframe, fpscpu, winw, winh);
JEVOIS_REGISTER_MODULE(ArUcoBlob)
Example of modified DNN module with custom post-processing.
void doprocess(jevois::InputFrame const &inframe, jevois::RawImage *outimg, jevois::OptGUIhelper *helper, bool idle)
Processing function implementation.
virtual void process(jevois::InputFrame &&inframe, jevois::GUIhelper &helper) override
Processing function with zero-copy and GUI on JeVois-Pro.
virtual void process(jevois::InputFrame &&inframe) override
Processing function, no video output.
CustomDNN(std::string const &instance)
Constructor.
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function with video output to USB on JeVois-A33.
virtual ~CustomDNN()
Virtual destructor for safe inheritance.
std::shared_ptr< MyPipeline > itsPipeline
std::shared_ptr< jevois::dnn::PostProcessor > getPostProcessor()
void onParamChange(jevois::dnn::pipeline::postproc const ¶m, jevois::dnn::pipeline::PostProc const &val) override
std::shared_ptr< jevois::dnn::PreProcessor > getPreProcessor()
std::vector< jevois::ObjDetect > const & getDetections()
void removeSubComponent(std::shared_ptr< Comp > &component)
void drawCircle(float x, float y, float r, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
void drawInputFrame(char const *name, InputFrame const &frame, int &x, int &y, unsigned short &w, unsigned short &h, bool noalias=false, bool casync=false)
bool startFrame(unsigned short &w, unsigned short &h)
void iinfo(jevois::InputFrame const &inframe, std::string const &fpscpu, unsigned short winw=0, unsigned short winh=0)
void drawImage(char const *name, RawImage const &img, int &x, int &y, unsigned short &w, unsigned short &h, bool noalias=false, bool isoverlay=false)
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)
void onParamChange(pipeline::zooroot const ¶m, std::string const &val) override
Pipeline(std::string const &instance)
std::shared_ptr< PostProcessor > itsPostProcessor
std::shared_ptr< PreProcessor > itsPreProcessor
std::vector< ObjDetect > itsDetections
void paste(RawImage const &src, RawImage &dest, int dx, int dy)
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async(Function &&f, Args &&... args)