Skip to content
Snippets Groups Projects
Commit 40eecf54 authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

improve aruco detection speed

parent 94280cb5
No related branches found
No related tags found
1 merge request!340aruco tags; headset position adjustment
Pipeline #29348 passed
...@@ -188,11 +188,11 @@ static void run(ftl::Configurable *root) { ...@@ -188,11 +188,11 @@ static void run(ftl::Configurable *root) {
root->on("quiet", quiet, false); root->on("quiet", quiet, false);
auto *pipeline = ftl::config::create<ftl::operators::Graph>(root, "pipeline"); auto *pipeline = ftl::config::create<ftl::operators::Graph>(root, "pipeline");
pipeline->append<ftl::operators::ArUco>("aruco")->value("enabled", false);
pipeline->append<ftl::operators::DetectAndTrack>("facedetection")->value("enabled", false); pipeline->append<ftl::operators::DetectAndTrack>("facedetection")->value("enabled", false);
pipeline->append<ftl::operators::DepthChannel>("depth"); // Ensure there is a depth channel pipeline->append<ftl::operators::DepthChannel>("depth"); // Ensure there is a depth channel
//pipeline->append<ftl::operators::ClipScene>("clipping")->value("enabled", false); //pipeline->append<ftl::operators::ClipScene>("clipping")->value("enabled", false);
pipeline->restore("vision_pipeline", { "clipping" }); pipeline->restore("vision_pipeline", { "clipping" });
pipeline->append<ftl::operators::ArUco>("aruco")->value("enabled", false);
auto h = creator->onFrameSet([sender,outstream,&stats_count,&latency,&frames,&stats_time,pipeline,&encodable,&previous_encodable](const ftl::data::FrameSetPtr &fs) { auto h = creator->onFrameSet([sender,outstream,&stats_count,&latency,&frames,&stats_time,pipeline,&encodable,&previous_encodable](const ftl::data::FrameSetPtr &fs) {
......
...@@ -121,6 +121,7 @@ class ArUco : public ftl::operators::Operator { ...@@ -121,6 +121,7 @@ class ArUco : public ftl::operators::Operator {
inline Operator::Type type() const override { return Operator::Type::OneToOne; } inline Operator::Type type() const override { return Operator::Type::OneToOne; }
bool apply(ftl::rgbd::Frame &in, ftl::rgbd::Frame &out, cudaStream_t stream) override; bool apply(ftl::rgbd::Frame &in, ftl::rgbd::Frame &out, cudaStream_t stream) override;
virtual void wait(cudaStream_t) override;
ftl::codecs::Channel channel_in_; ftl::codecs::Channel channel_in_;
ftl::codecs::Channel channel_out_; ftl::codecs::Channel channel_out_;
...@@ -129,6 +130,7 @@ class ArUco : public ftl::operators::Operator { ...@@ -129,6 +130,7 @@ class ArUco : public ftl::operators::Operator {
bool estimate_pose_; bool estimate_pose_;
float marker_size_; float marker_size_;
cv::Mat tmp_; cv::Mat tmp_;
std::future<void> job_;
cv::Ptr<cv::aruco::Dictionary> dictionary_; cv::Ptr<cv::aruco::Dictionary> dictionary_;
cv::Ptr<cv::aruco::DetectorParameters> params_; cv::Ptr<cv::aruco::DetectorParameters> params_;
......
...@@ -40,17 +40,23 @@ static Eigen::Matrix4d matrix(cv::Vec3d &rvec, cv::Vec3d &tvec) { ...@@ -40,17 +40,23 @@ static Eigen::Matrix4d matrix(cv::Vec3d &rvec, cv::Vec3d &tvec) {
} }
ArUco::ArUco(ftl::operators::Graph *g, ftl::Configurable *cfg) : ftl::operators::Operator(g, cfg) { ArUco::ArUco(ftl::operators::Graph *g, ftl::Configurable *cfg) : ftl::operators::Operator(g, cfg) {
dictionary_ = cv::aruco::getPredefinedDictionary(cfg->value("dictionary", 0)); dictionary_ = cv::aruco::getPredefinedDictionary(
cfg->value("dictionary", int(cv::aruco::DICT_4X4_50)));
params_ = cv::aruco::DetectorParameters::create(); params_ = cv::aruco::DetectorParameters::create();
params_->cornerRefinementMethod = cv::aruco::CORNER_REFINE_CONTOUR; params_->cornerRefinementMethod = cv::aruco::CORNER_REFINE_CONTOUR;
params_->cornerRefinementMinAccuracy = 0.01; params_->cornerRefinementMinAccuracy = 0.01;
params_->cornerRefinementMaxIterations = 20; params_->cornerRefinementMaxIterations = 20;
params_->adaptiveThreshWinSizeMin = 7;
params_->adaptiveThreshWinSizeMax = 17;
params_->adaptiveThreshWinSizeStep = 10;
channel_in_ = Channel::Colour; channel_in_ = Channel::Colour;
channel_out_ = Channel::Shapes3D; channel_out_ = Channel::Shapes3D;
cfg->on("dictionary", [this,cfg]() { cfg->on("dictionary", [this,cfg]() {
dictionary_ = cv::aruco::getPredefinedDictionary(cfg->value("dictionary", 0)); dictionary_ = cv::aruco::getPredefinedDictionary(
cfg->value("dictionary", 0));
}); });
} }
...@@ -60,6 +66,7 @@ bool ArUco::apply(Frame &in, Frame &out, cudaStream_t) { ...@@ -60,6 +66,7 @@ bool ArUco::apply(Frame &in, Frame &out, cudaStream_t) {
estimate_pose_ = config()->value("estimate_pose", true); estimate_pose_ = config()->value("estimate_pose", true);
marker_size_ = config()->value("marker_size", 0.1f); marker_size_ = config()->value("marker_size", 0.1f);
job_ = ftl::pool.push([this, &in, &out](int) {
std::vector<Vec3d> rvecs; std::vector<Vec3d> rvecs;
std::vector<Vec3d> tvecs; std::vector<Vec3d> tvecs;
std::vector<std::vector<cv::Point2f>> corners; std::vector<std::vector<cv::Point2f>> corners;
...@@ -97,5 +104,12 @@ bool ArUco::apply(Frame &in, Frame &out, cudaStream_t) { ...@@ -97,5 +104,12 @@ bool ArUco::apply(Frame &in, Frame &out, cudaStream_t) {
} }
out.create<list<Shape3D>>(channel_out_).list = result; out.create<list<Shape3D>>(channel_out_).list = result;
});
return true; return true;
} }
void ArUco::wait(cudaStream_t) {
if (job_.valid()) {
job_.wait();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment