-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from rogy-AquaLab/imshow
imshow
- Loading branch information
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(imshow) | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
# find dependencies | ||
find_package(ament_cmake REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(sensor_msgs REQUIRED) | ||
find_package(cv_bridge REQUIRED) | ||
find_package(image_transport REQUIRED) | ||
find_package(OpenCV REQUIRED) | ||
# uncomment the following section in order to fill in | ||
# further dependencies manually. | ||
# find_package(<dependency> REQUIRED) | ||
|
||
# Create executable | ||
add_executable(imshow src/imshow.cpp src/main.cpp) | ||
target_include_directories(imshow | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:include> | ||
${OpenCV_INCLUDE_DIRS} | ||
) | ||
|
||
# Link dependencies | ||
ament_target_dependencies(imshow rclcpp sensor_msgs cv_bridge image_transport) | ||
|
||
target_link_libraries(imshow ${OpenCV_LIBRARIES}) | ||
|
||
# Install targets | ||
install(TARGETS | ||
imshow | ||
DESTINATION lib/${PROJECT_NAME}) | ||
|
||
install(DIRECTORY launch | ||
DESTINATION share/${PROJECT_NAME}) | ||
|
||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# imshow | ||
|
||
USBカメラの映像を映す | ||
|
||
## Nodes | ||
|
||
- `Imshow`: 映像を映す | ||
|
||
## Executables | ||
|
||
- `imshow`: `imshow`Nodeをspin | ||
|
||
|
||
## Launches | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <cv_bridge/cv_bridge.hpp> | ||
#include <opencv2/opencv.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
#include <sensor_msgs/msg/image.hpp> | ||
|
||
class Imshow : public rclcpp::Node { | ||
public: | ||
Imshow(); | ||
|
||
private: | ||
void image_callback(const sensor_msgs::msg::Image::SharedPtr msg); | ||
rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr subscription_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from launch import LaunchDescription | ||
from launch_ros.actions import Node | ||
|
||
|
||
def generate_launch_description(): | ||
return LaunchDescription([ | ||
Node( | ||
package="imshow", | ||
executable="imshow", | ||
namespace="app", | ||
remappings=[("/app/camera/image", "/packet/camera/image")] | ||
) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>imshow</name> | ||
<version>0.0.0</version> | ||
<description>ROS 2 package for receiving images</description> | ||
<maintainer email="[email protected]">hiro</maintainer> | ||
<license>MIT License</license> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<build_depend>rclcpp</build_depend> | ||
<build_depend>sensor_msgs</build_depend> | ||
<build_depend>cv_bridge</build_depend> | ||
<build_depend>image_transport</build_depend> | ||
<exec_depend>rclcpp</exec_depend> | ||
<exec_depend>sensor_msgs</exec_depend> | ||
<exec_depend>cv_bridge</exec_depend> | ||
<exec_depend>image_transport</exec_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "imshow/imshow.hpp" | ||
|
||
Imshow::Imshow() : Node("imshow") { | ||
subscription_ = this->create_subscription<sensor_msgs::msg::Image>( | ||
"camera/image", | ||
10, | ||
std::bind(&Imshow::image_callback, this, std::placeholders::_1) | ||
); | ||
} | ||
|
||
void Imshow::image_callback(const sensor_msgs::msg::Image::SharedPtr msg) { | ||
try { | ||
const cv::Mat frame = cv_bridge::toCvCopy(msg, "bgr8")->image; | ||
cv::imshow("Received Image", frame); | ||
cv::waitKey(1); | ||
} catch (const cv_bridge::Exception& e) { | ||
RCLCPP_ERROR(this->get_logger(), "cv_bridge exception: %s", e.what()); | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "imshow/imshow.hpp" | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
int main(int argc, char* argv[]) { | ||
rclcpp::init(argc, argv); | ||
auto node = std::make_shared<Imshow>(); | ||
rclcpp::spin(node); | ||
rclcpp::shutdown(); | ||
return 0; | ||
} |