10 #include <experimental/filesystem>
14 #include <opencv2/core.hpp>
15 #include <opencv2/imgcodecs.hpp>
16 #include <opencv2/highgui.hpp>
17 #include <opencv2/objdetect.hpp>
18 #include <opencv2/imgproc.hpp>
20 #include <cv_bridge/cv_bridge.h>
21 #include <std_msgs/msg/header.hpp>
22 #include <sensor_msgs/image_encodings.hpp>
31 namespace fs = std::experimental::filesystem;
38 auto qosReliable = galaxis::ros::get_qos_profile(galaxis::ros::QoS_Profile_t::QOS_RELIABLE);
41 galaxis::ros::TOPIC_CAMERA_RAW,
52 cv::Mat image = cv_bridge::toCvShare(p_ImgMsg,
"bgr8")->image;
54 bool foundQR = this->
m_detector.detect(image, boundingBox);
59 this->
drawBox(image, boundingBox);
72 log(
"Sending message: QR Code found.");
75 this->
publishQR(p_ImgMsg->header.stamp,
true);
78 log(
"Sending message: QR Code NOT found.");
79 this->
publishQR(p_ImgMsg->header.stamp,
false);
83 std::this_thread::sleep_for(std::chrono::milliseconds(250));
90 cv::VideoCapture cap = cv::VideoCapture(path);
92 log_error(
"Error openning video stream or file");
94 cv::Mat frame, boundingBox;
97 while(cap.isOpened()){
98 bool ret = cap.read(frame);
102 if(frameCounter == cap.get(cv::CAP_PROP_FRAME_COUNT)){
104 cap.set(cv::CAP_PROP_POS_FRAMES, 0);
108 bool foundQR =
m_detector.detect(frame, boundingBox);
115 cv::imshow(
"detection", frame);
120 this->
publishQR(this->get_clock()->now(), foundQR);
126 std::unique_ptr<QRCodeDetectType> qrMsgUPtr = std::make_unique<QRCodeDetectType>();
127 qrMsgUPtr->header.stamp = stamp;
128 qrMsgUPtr->detected = detected;
145 float percentage = 0.3;
146 cv::Point2i topLeft = cv::Point2i(bbox.at<
float>(0,0),bbox.at<
float>(0,1));
147 cv::Point2i topRight = cv::Point2i(bbox.at<
float>(1,0),bbox.at<
float>(1,1));
148 cv::Point2i botRight = cv::Point2i(bbox.at<
float>(2,0),bbox.at<
float>(2,1));
149 cv::Point2i botLeft = cv::Point2i(bbox.at<
float>(3,0),bbox.at<
float>(3,1));
155 return std::abs(topLeft.y - topRight.y) < percentage * image.rows&&
156 std::abs(topRight.x - botRight.x) < percentage * image.cols&&
157 std::abs(botRight.y - botLeft.y) < percentage * image.rows&&
158 std::abs(botLeft.x - topLeft.x) < percentage * image.cols;
163 for(
int i = 0 ; i < n ; i++){
166 cv::Point2i(bbox.at<
float>(i,0),bbox.at<
float>(i,1)),
167 cv::Point2i(bbox.at<
float>((i+1) % n,0), bbox.at<
float>((i+1) % n,1)), cv::Scalar(255,0,0),