Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ add_library(${PROJECT_NAME} SHARED
"src/${PROJECT_NAME}/utils/color.cpp"
"src/${PROJECT_NAME}/utils/contours.cpp"
"src/${PROJECT_NAME}/utils/circle.cpp"
"src/${PROJECT_NAME}/utils/rect.cpp"
"src/${PROJECT_NAME}/node/ninshiki_cpp_node.cpp")

add_library(${PROJECT_NAME}_exported SHARED
Expand All @@ -59,7 +60,8 @@ add_library(${PROJECT_NAME}_exported SHARED
"src/${PROJECT_NAME}/detector/lbp_detector.cpp"
"src/${PROJECT_NAME}/utils/color.cpp"
"src/${PROJECT_NAME}/utils/contours.cpp"
"src/${PROJECT_NAME}/utils/circle.cpp")
"src/${PROJECT_NAME}/utils/circle.cpp"
"src/${PROJECT_NAME}/utils/rect.cpp")

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
43 changes: 43 additions & 0 deletions include/ninshiki_cpp/utils/rect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2024 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__RECT_HPP_
#define NINSHIKI_CPP__UTILS__RECT_HPP_

#include <opencv2/opencv.hpp>

namespace ninshiki_cpp::utils
{

class Rect
{
private:
cv::Rect rect;

public:
Rect(const cv::Rect & rect);
const cv::Mat & get_binary_mat(const cv::Size & mat_size, int line_size = cv::FILLED) const;

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

} // namespace ninshiki_cpp::utils

#endif // NINSHIKI_CPP__UTILS__RECT_HPP_
42 changes: 42 additions & 0 deletions src/ninshiki_cpp/utils/rect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2024 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/rect.hpp"

namespace ninshiki_cpp::utils
{

Rect::Rect(const cv::Rect & rect) : rect(rect) {}

const cv::Mat & Rect::get_binary_mat(const cv::Size & mat_size, int line_size) const
{
cv::Mat binary_mat(mat_size, CV_8UC1, cv::Scalar(0));

cv::rectangle(binary_mat, rect, cv::Scalar(255), line_size);

return binary_mat;
}

const cv::Point2f & Rect::get_center() const
{
return cv::Point2f(rect.x + rect.width / 2, rect.y + rect.height / 2);
}

} // namespace ninshiki_cpp::utils
Loading