JeVoisBase
1.20
JeVois Smart Embedded Machine Vision Toolkit Base Modules
|
Share this page: |
|
|
|
|
|
|
Go to the documentation of this file.
26 #include <opencv2/imgproc/imgproc.hpp>
34 "blob1, etc for parameters and serial messages",
151 public jevois::Parameter<numtrack>
160 itsArUco = addSubComponent<ArUco>(
"aruco");
171 for (
size_t i = 0; i < numtrack::get(); ++i)
212 try { f.get(); }
catch (...) {
LERROR(
"Ooops, some blob detector threw -- IGNORED"); }
217 for (
auto const & c : cc.second)
224 void detectArUco(cv::Mat cvimg, std::vector<int> & ids, std::vector<std::vector<cv::Point2f>> & corners,
225 std::vector<cv::Vec3d> & rvecs, std::vector<cv::Vec3d> & tvecs,
228 itsArUco->detectMarkers(cvimg, ids, corners);
230 if (
itsArUco->dopose::get() && ids.empty() ==
false)
231 itsArUco->estimatePoseSingleMarkers(corners, rvecs, tvecs);
234 if (outimg)
itsArUco->drawDetections(*outimg, 3,
h+2, ids, corners, rvecs, tvecs);
247 cv::cvtColor(imgbgr,
itsImgHsv, cv::COLOR_BGR2HSV);
259 std::vector<int> ids; std::vector<std::vector<cv::Point2f> > corners; std::vector<cv::Vec3d> rvecs, tvecs;
263 itsArUco->sendSerial(
this, ids, corners,
w,
h, rvecs, tvecs);
278 inimg.
require(
"input",
w,
h, V4L2_PIX_FMT_YUYV);
285 outimg = outframe.get();
294 cv::cvtColor(imgbgr,
itsImgHsv, cv::COLOR_BGR2HSV);
309 std::vector<int> ids; std::vector<std::vector<cv::Point2f> > corners; std::vector<cv::Vec3d> rvecs, tvecs;
310 detectArUco(cvimg, ids, corners, rvecs, tvecs,
h, &outimg);
313 itsArUco->sendSerial(
this, ids, corners,
w,
h, rvecs, tvecs);
324 int color = (cc.first.back() -
'0') * 123;
325 cv::drawContours(outuc2, cc.second, -1,
color, 2, 8);
326 for (
auto const & cont : cc.second)
328 cv::Moments moment = cv::moments(cont);
329 double const area = moment.m00;
330 int const x =
int(moment.m10 /
area + 0.4999);
331 int const y =
int(moment.m01 /
area + 0.4999);
338 std::string
str =
"Detected ";
343 std::string
const & fpscpu = timer.
stop();
356 std::vector<std::shared_ptr<BlobDetector> >
itsBlobs;
358 std::map<std::string, std::vector<std::vector<cv::Point>>>
itsContours;
const std::string & instanceName() const
void sendSerialContour2D(unsigned int camw, unsigned int camh, std::vector< cv::Point_< T > > points, std::string const &id="", std::string const &extra="")
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async(Function &&f, Args &&... args)
std::vector< std::vector< cv::Point > > detect(cv::Mat const &imghsv)
Detect blobs, each is represented as a contour (vector of (x,y) coordinates)
virtual void process(jevois::InputFrame &&inframe) override
Processing function, no USB video output.
std::vector< std::shared_ptr< BlobDetector > > itsBlobs
void postInit() override
Post-init: instantiate the blob detectors.
void drawCircle(RawImage &img, int x, int y, unsigned int rad, unsigned int thick, unsigned int col)
void sendBlobs(unsigned int w, unsigned int h)
Gather our blob threads and send/draw the results.
std::shared_ptr< ArUco > itsArUco
void removeSubComponent(std::shared_ptr< Comp > &component)
cv::Mat convertToCvBGR(RawImage const &src)
cv::Mat convertToCvGray(RawImage const &src)
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
virtual ~ArUcoBlob()
Virtual destructor for safe inheritance.
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function, with USB video output.
void detectBlobs()
Detect blobs in parallel threads.
void writeText(RawImage &img, std::string const &txt, int x, int y, unsigned int col, Font font=Font6x10)
std::vector< std::future< void > > itsBlobFuts
double area(const std::vector< Point2D< T > > &polygon, const bool getsigned=false)
What is the area of a polygon?
Combined ArUco marker + multiple color-based object detection.
const std::string & stop(double *seconds)
ArUcoBlob(std::string const &instance)
Constructor.
void drawFilledRect(RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int col)
StdModule(std::string const &instance)
JEVOIS_REGISTER_MODULE(ArUcoBlob)
std::string to_string(T const &val)
cv::Mat cvImage(RawImage const &src)
void detectArUco(cv::Mat cvimg, std::vector< int > &ids, std::vector< std::vector< cv::Point2f >> &corners, std::vector< cv::Vec3d > &rvecs, std::vector< cv::Vec3d > &tvecs, unsigned int h, jevois::RawImage *outimg=nullptr)
Detect ArUcos.
void paste(RawImage const &src, RawImage &dest, int dx, int dy)
std::map< std::string, std::vector< std::vector< cv::Point > > > itsContours
void preUninit() override