Skip to content

Commit

Permalink
Merge pull request #14 from ichiro-its/enhancement/refactor-ninshiki
Browse files Browse the repository at this point in the history
[Enhancement] - Refactor Ninshiki
  • Loading branch information
FaaizHaikal authored Jun 5, 2024
2 parents 15ee37f + 61058e4 commit 1d6b13f
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/circle.cpp"
"src/${PROJECT_NAME}/node/ninshiki_cpp_node.cpp"
"src/${PROJECT_NAME}/utils/utils.cpp")

Expand Down
2 changes: 1 addition & 1 deletion include/ninshiki_cpp/node/ninshiki_cpp_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class NinshikiCppNode
rclcpp::TimerBase::SharedPtr node_timer;

rclcpp::Publisher<DetectedObjects>::SharedPtr detected_object_publisher;
rclcpp::Publisher<Contours>::SharedPtr field_segmentation_publisher;
rclcpp::Publisher<Contours>::SharedPtr color_segmentation_publisher;
rclcpp::Subscription<Image>::SharedPtr image_subscriber;

std::shared_ptr<DnnDetector> dnn_detection;
Expand Down
49 changes: 49 additions & 0 deletions include/ninshiki_cpp/utils/circle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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__CIRCLE_HPP_
#define NINSHIKI_CPP__UTILS__CIRCLE_HPP_

#include <opencv2/opencv.hpp>
#include <vector>

namespace ninshiki_cpp::utils
{

class Circle
{
private:

cv::Point2f center;
float radius;

public:

Circle(const std::vector<cv::Point> & contour);

void draw(cv::Mat & image, int line_size) const;

const cv::Point2f & get_center() const;
const float get_radius() const;
};

} // namespace ninshiki_cpp::utils

#endif // NINSHIKI_CPP__UTILS__CIRCLE_HPP_
4 changes: 2 additions & 2 deletions src/ninshiki_cpp/node/ninshiki_cpp_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ NinshikiCppNode::NinshikiCppNode(
{
detected_object_publisher = node->create_publisher<DetectedObjects>(
get_node_prefix() + "/dnn_detection", 10);
field_segmentation_publisher = node->create_publisher<Contours>(
color_segmentation_publisher = node->create_publisher<Contours>(
get_node_prefix() + "/color_detection", 10);

image_subscriber =
Expand All @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions src/ninshiki_cpp/utils/circle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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/circle.hpp"

namespace ninshiki_cpp::utils
{

Circle::Circle(const std::vector<cv::Point> & contour)
: center(cv::Point2f(-1, -1)), radius(0.0)
{
cv::minEnclosingCircle(contour, center, radius);
}

void Circle::draw(cv::Mat & image, int line_size) const
{
cv::circle(image, center, radius, cv::Scalar(0, 255, 238), line_size);
}

const cv::Point2f & Circle::get_center() const
{
return center;
}

const float Circle::get_radius() const
{
return radius;
}

} // namespace ninshiki_cpp::utils

0 comments on commit 1d6b13f

Please sign in to comment.