From beb09b63969bcb6d1949c9e57b39d7d63e7b5bf1 Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Thu, 11 Apr 2024 01:35:32 +0700 Subject: [PATCH 01/13] refactor: change variable name --- include/ninshiki_cpp/node/ninshiki_cpp_node.hpp | 2 +- src/ninshiki_cpp/node/ninshiki_cpp_node.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/ninshiki_cpp/node/ninshiki_cpp_node.hpp b/include/ninshiki_cpp/node/ninshiki_cpp_node.hpp index f6deb2b..75730cd 100644 --- a/include/ninshiki_cpp/node/ninshiki_cpp_node.hpp +++ b/include/ninshiki_cpp/node/ninshiki_cpp_node.hpp @@ -65,7 +65,7 @@ class NinshikiCppNode rclcpp::TimerBase::SharedPtr node_timer; rclcpp::Publisher::SharedPtr detected_object_publisher; - rclcpp::Publisher::SharedPtr field_segmentation_publisher; + rclcpp::Publisher::SharedPtr color_segmentation_publisher; rclcpp::Subscription::SharedPtr image_subscriber; std::shared_ptr dnn_detection; diff --git a/src/ninshiki_cpp/node/ninshiki_cpp_node.cpp b/src/ninshiki_cpp/node/ninshiki_cpp_node.cpp index a5cfff2..58c02f2 100644 --- a/src/ninshiki_cpp/node/ninshiki_cpp_node.cpp +++ b/src/ninshiki_cpp/node/ninshiki_cpp_node.cpp @@ -36,7 +36,7 @@ NinshikiCppNode::NinshikiCppNode( { detected_object_publisher = node->create_publisher( get_node_prefix() + "/dnn_detection", 10); - field_segmentation_publisher = node->create_publisher( + color_segmentation_publisher = node->create_publisher( get_node_prefix() + "/color_detection", 10); image_subscriber = @@ -63,7 +63,7 @@ void NinshikiCppNode::publish() detected_object_publisher->publish(dnn_detection->detection_result); color_detection->detection(hsv_frame); - field_segmentation_publisher->publish(color_detection->detection_result); + color_segmentation_publisher->publish(color_detection->detection_result); lbp_detection->detection(received_frame); detected_object_publisher->publish(lbp_detection->detection_result); From 9ca90055ae2338b957f96c0130b0da7c38496e14 Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Thu, 11 Apr 2024 01:36:36 +0700 Subject: [PATCH 02/13] feat: circle shaped contours --- CMakeLists.txt | 1 + include/ninshiki_cpp/utils/circles.hpp | 56 ++++++++++++++++++ src/ninshiki_cpp/utils/circles.cpp | 79 ++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 include/ninshiki_cpp/utils/circles.hpp create mode 100644 src/ninshiki_cpp/utils/circles.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ccbc92a..74d0c2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ add_library(${PROJECT_NAME} SHARED "src/${PROJECT_NAME}/node/ninshiki_cpp_node.cpp" "src/${PROJECT_NAME}/utils/color.cpp" "src/${PROJECT_NAME}/utils/contours.cpp" + "src/${PROJECT_NAME}/utils/circles.cpp" "src/${PROJECT_NAME}/node/ninshiki_cpp_node.cpp" "src/${PROJECT_NAME}/utils/utils.cpp") diff --git a/include/ninshiki_cpp/utils/circles.hpp b/include/ninshiki_cpp/utils/circles.hpp new file mode 100644 index 0000000..8b40205 --- /dev/null +++ b/include/ninshiki_cpp/utils/circles.hpp @@ -0,0 +1,56 @@ +// Copyright (c) 2021 ICHIRO ITS +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#ifndef NINSHIKI_CPP__UTILS__CIRCLES_HPP_ +#define NINSHIKI_CPP__UTILS__CIRCLES_HPP_ + +#include +#include + +namespace ninshiki_cpp::utils +{ + +class Circles +{ +private: + + std::vector centers; + std::vector radiuses; + +public: + + Circles(); + Circles(std::vector> contours) { find(contours); } + + cv::Mat get_binary_mat(cv::Size mat_size) { return get_binary_mat_line(mat_size, cv::FILLED); } + cv::Mat get_binary_mat_line(cv::Size mat_size, int line_size); + + std::vector get_centers() { return centers; } + std::vector get_radiuses() { return radiuses; } + + cv::Point get_first_center(); + float get_first_radiuses(); + + void find(std::vector> contours); +}; + +} // namespace ninshiki_cpp::utils + +#endif // NINSHIKI_CPP__UTILS__CIRCLES_HPP_ \ No newline at end of file diff --git a/src/ninshiki_cpp/utils/circles.cpp b/src/ninshiki_cpp/utils/circles.cpp new file mode 100644 index 0000000..7b4bb6a --- /dev/null +++ b/src/ninshiki_cpp/utils/circles.cpp @@ -0,0 +1,79 @@ +// Copyright (c) 2021 ICHIRO ITS +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include "ninshiki_cpp/utils/circles.hpp" + +namespace ninshiki_cpp::utils +{ + +Circles::Circles() +{ + centers.clear(); + radiuses.clear(); +} + +cv::Mat Circles::get_binary_mat_line(cv::Size mat_size, int line_size) +{ + cv::Mat binary_mat(mat_size, CV_8UC1); + binary_mat = cv::Scalar(0); + + if (centers.size() > 0 && radiuses.size() > 0) + { + for (unsigned int i = 0; i < centers.size() && i < radiuses.size(); i++) + { + cv::circle(binary_mat, centers[i], radiuses[i], 255, line_size); + } + } + + return binary_mat; +} + +cv::Point Circles::get_first_center() +{ + if (centers.size() <= 0) + return cv::Point(-1, -1); + + return centers[0]; +} + +float Circles::get_first_radiuses() +{ + if (radiuses.size() <= 0) + return 0; + + return radiuses[0]; +} + +void Circles::find(std::vector> contours) +{ + centers.clear(); + radiuses.clear(); + + for (std::vector &contour : contours) + { + cv::Point2f center; + float radius; + cv::minEnclosingCircle(cv::Mat(contour), center, radius); + + centers.push_back(center); + radiuses.push_back(radius); + } +} +} // namespace ninshiki_cpp::utils \ No newline at end of file From be44ee1d8fe7099a6e5003dd03fef703abef31f2 Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Tue, 21 May 2024 00:30:49 +0700 Subject: [PATCH 03/13] fix: add eof line --- src/ninshiki_cpp/utils/circles.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ninshiki_cpp/utils/circles.cpp b/src/ninshiki_cpp/utils/circles.cpp index 7b4bb6a..9d44fcd 100644 --- a/src/ninshiki_cpp/utils/circles.cpp +++ b/src/ninshiki_cpp/utils/circles.cpp @@ -76,4 +76,5 @@ void Circles::find(std::vector> contours) radiuses.push_back(radius); } } -} // namespace ninshiki_cpp::utils \ No newline at end of file + +} // namespace ninshiki_cpp::utils From 7194c89213a24131e12a03a349831f14431032f7 Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Mon, 27 May 2024 20:40:49 +0700 Subject: [PATCH 04/13] fix: add missing EOF line --- include/ninshiki_cpp/utils/circles.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ninshiki_cpp/utils/circles.hpp b/include/ninshiki_cpp/utils/circles.hpp index 8b40205..f9eb81b 100644 --- a/include/ninshiki_cpp/utils/circles.hpp +++ b/include/ninshiki_cpp/utils/circles.hpp @@ -53,4 +53,4 @@ class Circles } // namespace ninshiki_cpp::utils -#endif // NINSHIKI_CPP__UTILS__CIRCLES_HPP_ \ No newline at end of file +#endif // NINSHIKI_CPP__UTILS__CIRCLES_HPP_ From da5f6992bedb2a27c20819a8dc6689b485784464 Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Mon, 27 May 2024 20:45:59 +0700 Subject: [PATCH 05/13] fix: pass const reference --- include/ninshiki_cpp/utils/circles.hpp | 8 ++++---- src/ninshiki_cpp/utils/circles.cpp | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/ninshiki_cpp/utils/circles.hpp b/include/ninshiki_cpp/utils/circles.hpp index f9eb81b..a443712 100644 --- a/include/ninshiki_cpp/utils/circles.hpp +++ b/include/ninshiki_cpp/utils/circles.hpp @@ -37,10 +37,10 @@ class Circles public: Circles(); - Circles(std::vector> contours) { find(contours); } + Circles(const std::vector> & contours) { find(contours); } - cv::Mat get_binary_mat(cv::Size mat_size) { return get_binary_mat_line(mat_size, cv::FILLED); } - cv::Mat get_binary_mat_line(cv::Size mat_size, int line_size); + cv::Mat get_binary_mat(const cv::Size & mat_size) { return get_binary_mat_line(mat_size, cv::FILLED); } + cv::Mat get_binary_mat_line(const cv::Size & mat_size, int line_size = cv::FILLED); std::vector get_centers() { return centers; } std::vector get_radiuses() { return radiuses; } @@ -48,7 +48,7 @@ class Circles cv::Point get_first_center(); float get_first_radiuses(); - void find(std::vector> contours); + void find(const std::vector> & contours); }; } // namespace ninshiki_cpp::utils diff --git a/src/ninshiki_cpp/utils/circles.cpp b/src/ninshiki_cpp/utils/circles.cpp index 9d44fcd..a76e9d5 100644 --- a/src/ninshiki_cpp/utils/circles.cpp +++ b/src/ninshiki_cpp/utils/circles.cpp @@ -24,12 +24,11 @@ namespace ninshiki_cpp::utils { Circles::Circles() +: centers{}, radiuses{} { - centers.clear(); - radiuses.clear(); } -cv::Mat Circles::get_binary_mat_line(cv::Size mat_size, int line_size) +cv::Mat Circles::get_binary_mat_line(const cv::Size & mat_size, int line_size) { cv::Mat binary_mat(mat_size, CV_8UC1); binary_mat = cv::Scalar(0); @@ -61,12 +60,12 @@ float Circles::get_first_radiuses() return radiuses[0]; } -void Circles::find(std::vector> contours) +void Circles::find(const std::vector> & contours) { centers.clear(); radiuses.clear(); - for (std::vector &contour : contours) + for (auto contour : contours) { cv::Point2f center; float radius; From 89b0a5edfa75af4bdde5738e4c57c9f9e500a8c2 Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Mon, 27 May 2024 20:47:06 +0700 Subject: [PATCH 06/13] refactor: use backward iteration --- src/ninshiki_cpp/utils/circles.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ninshiki_cpp/utils/circles.cpp b/src/ninshiki_cpp/utils/circles.cpp index a76e9d5..65c0a4d 100644 --- a/src/ninshiki_cpp/utils/circles.cpp +++ b/src/ninshiki_cpp/utils/circles.cpp @@ -35,10 +35,10 @@ cv::Mat Circles::get_binary_mat_line(const cv::Size & mat_size, int line_size) if (centers.size() > 0 && radiuses.size() > 0) { - for (unsigned int i = 0; i < centers.size() && i < radiuses.size(); i++) - { - cv::circle(binary_mat, centers[i], radiuses[i], 255, line_size); - } + for (int i = std::min(centers.size(), radiuses.size()) - 1; i >= 0; --i) + { + cv::circle(binary_mat, centers[i], radiuses[i], 255, line_size); + } } return binary_mat; From 34913d0d5da2aebc7c9b84eaa8e0ed7df51b0e1b Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Mon, 27 May 2024 20:48:43 +0700 Subject: [PATCH 07/13] fix: use std::vector::empty --- src/ninshiki_cpp/utils/circles.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ninshiki_cpp/utils/circles.cpp b/src/ninshiki_cpp/utils/circles.cpp index 65c0a4d..7f00861 100644 --- a/src/ninshiki_cpp/utils/circles.cpp +++ b/src/ninshiki_cpp/utils/circles.cpp @@ -46,7 +46,7 @@ cv::Mat Circles::get_binary_mat_line(const cv::Size & mat_size, int line_size) cv::Point Circles::get_first_center() { - if (centers.size() <= 0) + if (centers.empty()) return cv::Point(-1, -1); return centers[0]; @@ -54,7 +54,7 @@ cv::Point Circles::get_first_center() float Circles::get_first_radiuses() { - if (radiuses.size() <= 0) + if (radiuses.empty()) return 0; return radiuses[0]; From dc15c94c86dce8a270f6be348c4db75f70e40c3a Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Mon, 27 May 2024 20:58:21 +0700 Subject: [PATCH 08/13] refactor: minimze function count --- include/ninshiki_cpp/utils/circles.hpp | 11 ++++------ src/ninshiki_cpp/utils/circles.cpp | 29 +++++++++----------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/include/ninshiki_cpp/utils/circles.hpp b/include/ninshiki_cpp/utils/circles.hpp index a443712..8684385 100644 --- a/include/ninshiki_cpp/utils/circles.hpp +++ b/include/ninshiki_cpp/utils/circles.hpp @@ -31,24 +31,21 @@ class Circles { private: - std::vector centers; + std::vector centers; std::vector radiuses; public: - Circles(); - Circles(const std::vector> & contours) { find(contours); } + Circles(const std::vector> & contours); cv::Mat get_binary_mat(const cv::Size & mat_size) { return get_binary_mat_line(mat_size, cv::FILLED); } cv::Mat get_binary_mat_line(const cv::Size & mat_size, int line_size = cv::FILLED); - std::vector get_centers() { return centers; } + std::vector get_centers() { return centers; } std::vector get_radiuses() { return radiuses; } - cv::Point get_first_center(); + cv::Point2f get_first_center(); float get_first_radiuses(); - - void find(const std::vector> & contours); }; } // namespace ninshiki_cpp::utils diff --git a/src/ninshiki_cpp/utils/circles.cpp b/src/ninshiki_cpp/utils/circles.cpp index 7f00861..2cb8864 100644 --- a/src/ninshiki_cpp/utils/circles.cpp +++ b/src/ninshiki_cpp/utils/circles.cpp @@ -23,9 +23,16 @@ namespace ninshiki_cpp::utils { -Circles::Circles() +Circles::Circles(const std::vector> & contours) : centers{}, radiuses{} { + centers.resize(contours.size()); + radiuses.resize(contours.size()); + + for (int i = contours.size() - 1; i >= 0; --i) + { + cv::minEnclosingCircle(cv::Mat(contours[i]), centers[i], radiuses[i]); + } } cv::Mat Circles::get_binary_mat_line(const cv::Size & mat_size, int line_size) @@ -44,10 +51,10 @@ cv::Mat Circles::get_binary_mat_line(const cv::Size & mat_size, int line_size) return binary_mat; } -cv::Point Circles::get_first_center() +cv::Point2f Circles::get_first_center() { if (centers.empty()) - return cv::Point(-1, -1); + return cv::Point2f(-1, -1); return centers[0]; } @@ -60,20 +67,4 @@ float Circles::get_first_radiuses() return radiuses[0]; } -void Circles::find(const std::vector> & contours) -{ - centers.clear(); - radiuses.clear(); - - for (auto contour : contours) - { - cv::Point2f center; - float radius; - cv::minEnclosingCircle(cv::Mat(contour), center, radius); - - centers.push_back(center); - radiuses.push_back(radius); - } -} - } // namespace ninshiki_cpp::utils From 3423399ce0f78c2c57b38eda6ba2c42c72be85be Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Tue, 28 May 2024 23:16:21 +0700 Subject: [PATCH 09/13] refactor: change circles to circle class --- CMakeLists.txt | 2 +- .../utils/{circles.hpp => circle.hpp} | 22 +++++------ .../utils/{circles.cpp => circle.cpp} | 38 +++++-------------- 3 files changed, 20 insertions(+), 42 deletions(-) rename include/ninshiki_cpp/utils/{circles.hpp => circle.hpp} (72%) rename src/ninshiki_cpp/utils/{circles.cpp => circle.cpp} (58%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74d0c2f..a292b75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ add_library(${PROJECT_NAME} SHARED "src/${PROJECT_NAME}/node/ninshiki_cpp_node.cpp" "src/${PROJECT_NAME}/utils/color.cpp" "src/${PROJECT_NAME}/utils/contours.cpp" - "src/${PROJECT_NAME}/utils/circles.cpp" + "src/${PROJECT_NAME}/utils/circle.cpp" "src/${PROJECT_NAME}/node/ninshiki_cpp_node.cpp" "src/${PROJECT_NAME}/utils/utils.cpp") diff --git a/include/ninshiki_cpp/utils/circles.hpp b/include/ninshiki_cpp/utils/circle.hpp similarity index 72% rename from include/ninshiki_cpp/utils/circles.hpp rename to include/ninshiki_cpp/utils/circle.hpp index 8684385..c1ddec3 100644 --- a/include/ninshiki_cpp/utils/circles.hpp +++ b/include/ninshiki_cpp/utils/circle.hpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#ifndef NINSHIKI_CPP__UTILS__CIRCLES_HPP_ -#define NINSHIKI_CPP__UTILS__CIRCLES_HPP_ +#ifndef NINSHIKI_CPP__UTILS__CIRCLE_HPP_ +#define NINSHIKI_CPP__UTILS__CIRCLE_HPP_ #include #include @@ -27,25 +27,21 @@ namespace ninshiki_cpp::utils { -class Circles +class Circle { private: - std::vector centers; - std::vector radiuses; + cv::Point2f center; + float radius; public: - Circles(const std::vector> & contours); - - cv::Mat get_binary_mat(const cv::Size & mat_size) { return get_binary_mat_line(mat_size, cv::FILLED); } - cv::Mat get_binary_mat_line(const cv::Size & mat_size, int line_size = cv::FILLED); + Circle(const std::vector & contour); - std::vector get_centers() { return centers; } - std::vector get_radiuses() { return radiuses; } + cv::Mat get_binary_mat_line(const cv::Size & mat_size, int line_size = cv::FILLED); - cv::Point2f get_first_center(); - float get_first_radiuses(); + cv::Point2f get_center(); + float get_radius(); }; } // namespace ninshiki_cpp::utils diff --git a/src/ninshiki_cpp/utils/circles.cpp b/src/ninshiki_cpp/utils/circle.cpp similarity index 58% rename from src/ninshiki_cpp/utils/circles.cpp rename to src/ninshiki_cpp/utils/circle.cpp index 2cb8864..8db4ca7 100644 --- a/src/ninshiki_cpp/utils/circles.cpp +++ b/src/ninshiki_cpp/utils/circle.cpp @@ -18,53 +18,35 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "ninshiki_cpp/utils/circles.hpp" +#include "ninshiki_cpp/utils/circle.hpp" namespace ninshiki_cpp::utils { -Circles::Circles(const std::vector> & contours) -: centers{}, radiuses{} +Circle::Circle(const std::vector & contour) +: center(cv::Point2f(-1, -1)), radius(0.0) { - centers.resize(contours.size()); - radiuses.resize(contours.size()); - - for (int i = contours.size() - 1; i >= 0; --i) - { - cv::minEnclosingCircle(cv::Mat(contours[i]), centers[i], radiuses[i]); - } + cv::minEnclosingCircle(cv::Mat(contour), center, radius); } -cv::Mat Circles::get_binary_mat_line(const cv::Size & mat_size, int line_size) +cv::Mat Circle::get_binary_mat_line(const cv::Size & mat_size, int line_size) { cv::Mat binary_mat(mat_size, CV_8UC1); binary_mat = cv::Scalar(0); - if (centers.size() > 0 && radiuses.size() > 0) - { - for (int i = std::min(centers.size(), radiuses.size()) - 1; i >= 0; --i) - { - cv::circle(binary_mat, centers[i], radiuses[i], 255, line_size); - } - } + cv::circle(binary_mat, center, radius, 255, line_size); return binary_mat; } -cv::Point2f Circles::get_first_center() +cv::Point2f Circle::get_center() { - if (centers.empty()) - return cv::Point2f(-1, -1); - - return centers[0]; + return center; } -float Circles::get_first_radiuses() +float Circle::get_radius() { - if (radiuses.empty()) - return 0; - - return radiuses[0]; + return radius; } } // namespace ninshiki_cpp::utils From 6e00e228150bfb8dab532600105757225c1adf22 Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Wed, 29 May 2024 19:24:40 +0700 Subject: [PATCH 10/13] refactor: const function and return const ref --- include/ninshiki_cpp/utils/circle.hpp | 6 +++--- src/ninshiki_cpp/utils/circle.cpp | 15 +++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/include/ninshiki_cpp/utils/circle.hpp b/include/ninshiki_cpp/utils/circle.hpp index c1ddec3..720be6f 100644 --- a/include/ninshiki_cpp/utils/circle.hpp +++ b/include/ninshiki_cpp/utils/circle.hpp @@ -38,10 +38,10 @@ class Circle Circle(const std::vector & contour); - cv::Mat get_binary_mat_line(const cv::Size & mat_size, int line_size = cv::FILLED); + void draw(cv::Mat & image, int line_size) const; - cv::Point2f get_center(); - float get_radius(); + const cv::Point2f & get_center() const; + const float & get_radius() const; }; } // namespace ninshiki_cpp::utils diff --git a/src/ninshiki_cpp/utils/circle.cpp b/src/ninshiki_cpp/utils/circle.cpp index 8db4ca7..7751b45 100644 --- a/src/ninshiki_cpp/utils/circle.cpp +++ b/src/ninshiki_cpp/utils/circle.cpp @@ -26,25 +26,20 @@ namespace ninshiki_cpp::utils Circle::Circle(const std::vector & contour) : center(cv::Point2f(-1, -1)), radius(0.0) { - cv::minEnclosingCircle(cv::Mat(contour), center, radius); + cv::minEnclosingCircle(contour, center, radius); } -cv::Mat Circle::get_binary_mat_line(const cv::Size & mat_size, int line_size) +void Circle::draw(cv::Mat & image, int line_size) const { - cv::Mat binary_mat(mat_size, CV_8UC1); - binary_mat = cv::Scalar(0); - - cv::circle(binary_mat, center, radius, 255, line_size); - - return binary_mat; + cv::circle(image, center, radius, 255, line_size); } -cv::Point2f Circle::get_center() +const cv::Point2f & Circle::get_center() const { return center; } -float Circle::get_radius() +const float & Circle::get_radius() const { return radius; } From 836eb53a4498ac4bf467ee95ed2c33610b205296 Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Thu, 30 May 2024 00:40:49 +0700 Subject: [PATCH 11/13] refactor: change circle color line --- src/ninshiki_cpp/utils/circle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ninshiki_cpp/utils/circle.cpp b/src/ninshiki_cpp/utils/circle.cpp index 7751b45..654aede 100644 --- a/src/ninshiki_cpp/utils/circle.cpp +++ b/src/ninshiki_cpp/utils/circle.cpp @@ -31,7 +31,7 @@ Circle::Circle(const std::vector & contour) void Circle::draw(cv::Mat & image, int line_size) const { - cv::circle(image, center, radius, 255, line_size); + cv::circle(image, center, radius, cv::Scalar(0, 255, 238), line_size); } const cv::Point2f & Circle::get_center() const From 6ab08f91fa7cc5bfe14aca89f9e034420c6b833a Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Fri, 31 May 2024 22:01:17 +0700 Subject: [PATCH 12/13] fix: fix float return type --- include/ninshiki_cpp/utils/circle.hpp | 2 +- src/ninshiki_cpp/utils/circle.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ninshiki_cpp/utils/circle.hpp b/include/ninshiki_cpp/utils/circle.hpp index 720be6f..4f5d914 100644 --- a/include/ninshiki_cpp/utils/circle.hpp +++ b/include/ninshiki_cpp/utils/circle.hpp @@ -41,7 +41,7 @@ class Circle void draw(cv::Mat & image, int line_size) const; const cv::Point2f & get_center() const; - const float & get_radius() const; + const float get_radius() const; }; } // namespace ninshiki_cpp::utils diff --git a/src/ninshiki_cpp/utils/circle.cpp b/src/ninshiki_cpp/utils/circle.cpp index 654aede..57cdb36 100644 --- a/src/ninshiki_cpp/utils/circle.cpp +++ b/src/ninshiki_cpp/utils/circle.cpp @@ -39,7 +39,7 @@ const cv::Point2f & Circle::get_center() const return center; } -const float & Circle::get_radius() const +const float Circle::get_radius() const { return radius; } From 61058e49fbefdf482d03306892e07b901a7f0b2c Mon Sep 17 00:00:00 2001 From: FaaizHaikal Date: Wed, 5 Jun 2024 19:37:33 +0700 Subject: [PATCH 13/13] fix: minor typo --- include/ninshiki_cpp/utils/circle.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ninshiki_cpp/utils/circle.hpp b/include/ninshiki_cpp/utils/circle.hpp index 4f5d914..67207e2 100644 --- a/include/ninshiki_cpp/utils/circle.hpp +++ b/include/ninshiki_cpp/utils/circle.hpp @@ -46,4 +46,4 @@ class Circle } // namespace ninshiki_cpp::utils -#endif // NINSHIKI_CPP__UTILS__CIRCLES_HPP_ +#endif // NINSHIKI_CPP__UTILS__CIRCLE_HPP_