mirror of
https://github.com/OSURoboticsClub/Rover_2017_2018.git
synced 2025-11-08 10:11:14 +00:00
Turned modified tutorial publisher into actual rover_camera node
This commit is contained in:
29
rover/rover_camera/CMakeLists.txt
Normal file
29
rover/rover_camera/CMakeLists.txt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
project(rover_camera)
|
||||||
|
|
||||||
|
find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport message_generation sensor_msgs)
|
||||||
|
|
||||||
|
# add the resized image message
|
||||||
|
|
||||||
|
catkin_package(CATKIN_DEPENDS cv_bridge image_transport message_runtime sensor_msgs)
|
||||||
|
|
||||||
|
find_package(OpenCV)
|
||||||
|
|
||||||
|
include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
# add the publisher example
|
||||||
|
add_executable(rover_camera src/rover_camera.cpp)
|
||||||
|
add_dependencies(rover_camera ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS})
|
||||||
|
target_link_libraries(rover_camera ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
|
||||||
|
|
||||||
|
|
||||||
|
# Mark executables and/or libraries for installation
|
||||||
|
install(TARGETS rover_camera
|
||||||
|
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||||
|
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||||
|
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
|
||||||
|
)
|
||||||
|
|
||||||
|
#install(FILES resized_plugins.xml
|
||||||
|
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
|
||||||
|
#)
|
||||||
22
rover/rover_camera/launch/example.launch
Normal file
22
rover/rover_camera/launch/example.launch
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<launch>
|
||||||
|
<group ns="cameras">
|
||||||
|
<node name="camera_name" pkg="rover_camera" type="rover_camera" launch-prefix="taskset -c 1" output="screen">
|
||||||
|
<param name="device_path" value="/dev/video0"/>
|
||||||
|
</node>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<node name="main_navigation" pkg="rover_camera" type="rover_camera" launch-prefix="taskset -c 2" output="screen" >
|
||||||
|
<param name="device_path" value="/dev/rover/camera_main_navigation" />
|
||||||
|
</node>
|
||||||
|
|
||||||
|
<node name="gimbal" pkg="rover_camera" type="rover_camera" launch-prefix="taskset -c 3" output="screen" >
|
||||||
|
<param name="device_path" value="/dev/rover/camera_gimbal" />
|
||||||
|
</node>
|
||||||
|
-->
|
||||||
|
|
||||||
|
</group>
|
||||||
|
|
||||||
|
<node name="image_view" pkg="image_view" type="image_view" launch-prefix="taskset -c 4" output="screen">
|
||||||
|
<remap from="image" to="/cameras/camera_name/image_720p"/>
|
||||||
|
</node>
|
||||||
|
</launch>
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
<package>
|
<package>
|
||||||
<name>image_transport_tutorial</name>
|
<name>rover_camera</name>
|
||||||
<version>0.0.0</version>
|
<version>0.0.0</version>
|
||||||
<description>Tutorial for image_transport. This is useful for the tutorials at http://wiki.ros.org/image_transport/Tutorials/</description>
|
<description>This package opens a camera on linux using OpenCV and publishes multiple streams at different resolutions</description>
|
||||||
<author>Vincent Rabaud</author>
|
<author>Corwin Perren</author>
|
||||||
<maintainer email="vincent.rabaud@gmail.com">Vincent Rabaud</maintainer>
|
<maintainer email="caperren@gmail.com">Corwin Perren</maintainer>
|
||||||
<license>Apache 2.0</license>
|
<license>Apache 2.0</license>
|
||||||
|
|
||||||
<build_depend>cv_bridge</build_depend>
|
<build_depend>cv_bridge</build_depend>
|
||||||
@@ -20,7 +20,4 @@
|
|||||||
|
|
||||||
<buildtool_depend>catkin</buildtool_depend>
|
<buildtool_depend>catkin</buildtool_depend>
|
||||||
|
|
||||||
<export>
|
|
||||||
<image_transport plugin="${prefix}/resized_plugins.xml"/>
|
|
||||||
</export>
|
|
||||||
</package>
|
</package>
|
||||||
@@ -13,23 +13,23 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
std::string capture_device_path;
|
std::string capture_device_path;
|
||||||
int fps;
|
int fps;
|
||||||
|
|
||||||
int large_image_width;
|
int large_image_width;
|
||||||
int large_image_height;
|
int large_image_height;
|
||||||
int small_image_width;
|
int small_image_width;
|
||||||
int small_image_height;
|
int small_image_height;
|
||||||
|
|
||||||
ros::init(argc, argv, "camera");
|
ros::init(argc, argv, "camera");
|
||||||
ros::NodeHandle node_handle("~");
|
ros::NodeHandle node_handle("~");
|
||||||
|
|
||||||
node_handle.param("device_path", capture_device_path, std::string("/dev/video0"));
|
node_handle.param("device_path", capture_device_path, std::string("/dev/video0"));
|
||||||
node_handle.param("fps", fps, 30);
|
node_handle.param("fps", fps, 30);
|
||||||
|
|
||||||
node_handle.param("large_image_width", large_image_width, 1280);
|
node_handle.param("large_image_width", large_image_width, 1280);
|
||||||
node_handle.param("large_image_height", large_image_height, 720);
|
node_handle.param("large_image_height", large_image_height, 720);
|
||||||
node_handle.param("small_image_width", small_image_width, 640);
|
node_handle.param("small_image_width", small_image_width, 640);
|
||||||
node_handle.param("small_image_height", small_image_height, 360);
|
node_handle.param("small_image_height", small_image_height, 360);
|
||||||
|
|
||||||
cv::VideoCapture cap(capture_device_path);
|
cv::VideoCapture cap(capture_device_path);
|
||||||
|
|
||||||
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
|
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
|
||||||
@@ -40,10 +40,10 @@ int main(int argc, char** argv)
|
|||||||
if(cap.isOpened() == false){
|
if(cap.isOpened() == false){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
image_transport::ImageTransport full_res_image_transport(node_handle);
|
image_transport::ImageTransport full_res_image_transport(node_handle);
|
||||||
image_transport::ImageTransport lower_res_image_transport(node_handle);
|
image_transport::ImageTransport lower_res_image_transport(node_handle);
|
||||||
|
|
||||||
image_transport::Publisher full_size_publisher = full_res_image_transport.advertise("image_720p", 1);
|
image_transport::Publisher full_size_publisher = full_res_image_transport.advertise("image_720p", 1);
|
||||||
image_transport::Publisher lower_size_publisher = lower_res_image_transport.advertise("image_360p", 1);
|
image_transport::Publisher lower_size_publisher = lower_res_image_transport.advertise("image_360p", 1);
|
||||||
|
|
||||||
@@ -51,24 +51,23 @@ int main(int argc, char** argv)
|
|||||||
cv::Mat image_smaller;
|
cv::Mat image_smaller;
|
||||||
|
|
||||||
ros::Rate loop_rate(fps + 5);
|
ros::Rate loop_rate(fps + 5);
|
||||||
|
|
||||||
|
|
||||||
while (node_handle.ok()) {
|
while (node_handle.ok()) {
|
||||||
|
|
||||||
cap.read(image);
|
cap.read(image);
|
||||||
|
|
||||||
if(!image.empty()){
|
if(!image.empty()){
|
||||||
cv::resize(image, image_smaller, cv::Size(small_image_width, small_image_height));
|
cv::resize(image, image_smaller, cv::Size(small_image_width, small_image_height));
|
||||||
|
|
||||||
sensor_msgs::ImagePtr full_res_message = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();
|
sensor_msgs::ImagePtr full_res_message = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();
|
||||||
sensor_msgs::ImagePtr lower_res_message = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image_smaller).toImageMsg();
|
sensor_msgs::ImagePtr lower_res_message = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image_smaller).toImageMsg();
|
||||||
|
|
||||||
full_size_publisher.publish(full_res_message);
|
full_size_publisher.publish(full_res_message);
|
||||||
lower_size_publisher.publish(lower_res_message);
|
lower_size_publisher.publish(lower_res_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ros::spinOnce();
|
ros::spinOnce();
|
||||||
loop_rate.sleep();
|
loop_rate.sleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.3)
|
|
||||||
project(rover_cameras)
|
|
||||||
|
|
||||||
## Compile as C++11, supported in ROS Kinetic and newer
|
|
||||||
# add_compile_options(-std=c++11)
|
|
||||||
|
|
||||||
## Find catkin macros and libraries
|
|
||||||
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
|
|
||||||
## is used, also find other catkin packages
|
|
||||||
find_package(catkin REQUIRED COMPONENTS
|
|
||||||
rospy
|
|
||||||
)
|
|
||||||
|
|
||||||
## System dependencies are found with CMake's conventions
|
|
||||||
# find_package(Boost REQUIRED COMPONENTS system)
|
|
||||||
|
|
||||||
|
|
||||||
## Uncomment this if the package has a setup.py. This macro ensures
|
|
||||||
## modules and global scripts declared therein get installed
|
|
||||||
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
|
|
||||||
# catkin_python_setup()
|
|
||||||
|
|
||||||
################################################
|
|
||||||
## Declare ROS messages, services and actions ##
|
|
||||||
################################################
|
|
||||||
|
|
||||||
## To declare and build messages, services or actions from within this
|
|
||||||
## package, follow these steps:
|
|
||||||
## * Let MSG_DEP_SET be the set of packages whose message types you use in
|
|
||||||
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
|
|
||||||
## * In the file package.xml:
|
|
||||||
## * add a build_depend tag for "message_generation"
|
|
||||||
## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
|
|
||||||
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
|
|
||||||
## but can be declared for certainty nonetheless:
|
|
||||||
## * add a run_depend tag for "message_runtime"
|
|
||||||
## * In this file (CMakeLists.txt):
|
|
||||||
## * add "message_generation" and every package in MSG_DEP_SET to
|
|
||||||
## find_package(catkin REQUIRED COMPONENTS ...)
|
|
||||||
## * add "message_runtime" and every package in MSG_DEP_SET to
|
|
||||||
## catkin_package(CATKIN_DEPENDS ...)
|
|
||||||
## * uncomment the add_*_files sections below as needed
|
|
||||||
## and list every .msg/.srv/.action file to be processed
|
|
||||||
## * uncomment the generate_messages entry below
|
|
||||||
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
|
|
||||||
|
|
||||||
## Generate messages in the 'msg' folder
|
|
||||||
# add_message_files(
|
|
||||||
# FILES
|
|
||||||
# Message1.msg
|
|
||||||
# Message2.msg
|
|
||||||
# )
|
|
||||||
|
|
||||||
## Generate services in the 'srv' folder
|
|
||||||
# add_service_files(
|
|
||||||
# FILES
|
|
||||||
# Service1.srv
|
|
||||||
# Service2.srv
|
|
||||||
# )
|
|
||||||
|
|
||||||
## Generate actions in the 'action' folder
|
|
||||||
# add_action_files(
|
|
||||||
# FILES
|
|
||||||
# Action1.action
|
|
||||||
# Action2.action
|
|
||||||
# )
|
|
||||||
|
|
||||||
## Generate added messages and services with any dependencies listed here
|
|
||||||
# generate_messages(
|
|
||||||
# DEPENDENCIES
|
|
||||||
# std_msgs # Or other packages containing msgs
|
|
||||||
# )
|
|
||||||
|
|
||||||
################################################
|
|
||||||
## Declare ROS dynamic reconfigure parameters ##
|
|
||||||
################################################
|
|
||||||
|
|
||||||
## To declare and build dynamic reconfigure parameters within this
|
|
||||||
## package, follow these steps:
|
|
||||||
## * In the file package.xml:
|
|
||||||
## * add a build_depend and a run_depend tag for "dynamic_reconfigure"
|
|
||||||
## * In this file (CMakeLists.txt):
|
|
||||||
## * add "dynamic_reconfigure" to
|
|
||||||
## find_package(catkin REQUIRED COMPONENTS ...)
|
|
||||||
## * uncomment the "generate_dynamic_reconfigure_options" section below
|
|
||||||
## and list every .cfg file to be processed
|
|
||||||
|
|
||||||
## Generate dynamic reconfigure parameters in the 'cfg' folder
|
|
||||||
# generate_dynamic_reconfigure_options(
|
|
||||||
# cfg/DynReconf1.cfg
|
|
||||||
# cfg/DynReconf2.cfg
|
|
||||||
# )
|
|
||||||
|
|
||||||
###################################
|
|
||||||
## catkin specific configuration ##
|
|
||||||
###################################
|
|
||||||
## The catkin_package macro generates cmake config files for your package
|
|
||||||
## Declare things to be passed to dependent projects
|
|
||||||
## INCLUDE_DIRS: uncomment this if your package contains header files
|
|
||||||
## LIBRARIES: libraries you create in this project that dependent projects also need
|
|
||||||
## CATKIN_DEPENDS: catkin_packages dependent projects also need
|
|
||||||
## DEPENDS: system dependencies of this project that dependent projects also need
|
|
||||||
catkin_package(
|
|
||||||
# INCLUDE_DIRS include
|
|
||||||
# LIBRARIES rover_cameras
|
|
||||||
# CATKIN_DEPENDS rospy
|
|
||||||
# DEPENDS system_lib
|
|
||||||
)
|
|
||||||
|
|
||||||
###########
|
|
||||||
## Build ##
|
|
||||||
###########
|
|
||||||
|
|
||||||
## Specify additional locations of header files
|
|
||||||
## Your package locations should be listed before other locations
|
|
||||||
include_directories(
|
|
||||||
# include
|
|
||||||
${catkin_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
|
|
||||||
## Declare a C++ library
|
|
||||||
# add_library(${PROJECT_NAME}
|
|
||||||
# src/${PROJECT_NAME}/rover_cameras.cpp
|
|
||||||
# )
|
|
||||||
|
|
||||||
## Add cmake target dependencies of the library
|
|
||||||
## as an example, code may need to be generated before libraries
|
|
||||||
## either from message generation or dynamic reconfigure
|
|
||||||
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
|
|
||||||
|
|
||||||
## Declare a C++ executable
|
|
||||||
## With catkin_make all packages are built within a single CMake context
|
|
||||||
## The recommended prefix ensures that target names across packages don't collide
|
|
||||||
# add_executable(${PROJECT_NAME}_node src/rover_cameras_node.cpp)
|
|
||||||
|
|
||||||
## Rename C++ executable without prefix
|
|
||||||
## The above recommended prefix causes long target names, the following renames the
|
|
||||||
## target back to the shorter version for ease of user use
|
|
||||||
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
|
|
||||||
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
|
|
||||||
|
|
||||||
## Add cmake target dependencies of the executable
|
|
||||||
## same as for the library above
|
|
||||||
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
|
|
||||||
|
|
||||||
## Specify libraries to link a library or executable target against
|
|
||||||
# target_link_libraries(${PROJECT_NAME}_node
|
|
||||||
# ${catkin_LIBRARIES}
|
|
||||||
# )
|
|
||||||
|
|
||||||
#############
|
|
||||||
## Install ##
|
|
||||||
#############
|
|
||||||
|
|
||||||
# all install targets should use catkin DESTINATION variables
|
|
||||||
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
|
|
||||||
|
|
||||||
## Mark executable scripts (Python etc.) for installation
|
|
||||||
## in contrast to setup.py, you can choose the destination
|
|
||||||
# install(PROGRAMS
|
|
||||||
# scripts/my_python_script
|
|
||||||
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
|
|
||||||
# )
|
|
||||||
|
|
||||||
## Mark executables and/or libraries for installation
|
|
||||||
# install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_node
|
|
||||||
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
||||||
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
||||||
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
|
|
||||||
# )
|
|
||||||
|
|
||||||
## Mark cpp header files for installation
|
|
||||||
# install(DIRECTORY include/${PROJECT_NAME}/
|
|
||||||
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
|
|
||||||
# FILES_MATCHING PATTERN "*.h"
|
|
||||||
# PATTERN ".svn" EXCLUDE
|
|
||||||
# )
|
|
||||||
|
|
||||||
## Mark other files for installation (e.g. launch and bag files, etc.)
|
|
||||||
# install(FILES
|
|
||||||
# # myfile1
|
|
||||||
# # myfile2
|
|
||||||
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
|
|
||||||
# )
|
|
||||||
|
|
||||||
#############
|
|
||||||
## Testing ##
|
|
||||||
#############
|
|
||||||
|
|
||||||
## Add gtest based cpp test target and link libraries
|
|
||||||
# catkin_add_gtest(${PROJECT_NAME}-test test/test_rover_cameras.cpp)
|
|
||||||
# if(TARGET ${PROJECT_NAME}-test)
|
|
||||||
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
|
|
||||||
# endif()
|
|
||||||
|
|
||||||
## Add folders to be run by python nosetests
|
|
||||||
# catkin_add_nosetests(test)
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<launch>
|
|
||||||
<group ns="cameras">
|
|
||||||
<node name="gimbal" pkg="cv_camera" type="cv_camera_node" output="screen" >
|
|
||||||
<param name="device_path" value="/dev/rover/camera_gimbal" />
|
|
||||||
<param name="image_width" value="640" />
|
|
||||||
<param name="image_height" value="360" />
|
|
||||||
</node>
|
|
||||||
</group>
|
|
||||||
</launch>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<launch>
|
|
||||||
<group ns="cameras">
|
|
||||||
<node name="gimbal" pkg="usb_cam" type="usb_cam_node" output="screen" >
|
|
||||||
<param name="video_device" value="/dev/rover/camera_gimbal" />
|
|
||||||
<param name="image_width" value="1280" />
|
|
||||||
<param name="image_height" value="720" />
|
|
||||||
<param name="pixel_format" value="mjpeg" />
|
|
||||||
<param name="camera_frame_id" value="usb_cam1" />
|
|
||||||
<param name="io_method" value="mmap"/>
|
|
||||||
</node>
|
|
||||||
</group>
|
|
||||||
</launch>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<launch>
|
|
||||||
<group ns="cameras">
|
|
||||||
<node name="main_navigation" pkg="cv_camera" type="cv_camera_node" output="screen" >
|
|
||||||
<param name="device_path" value="/dev/rover/camera_main_navigation" />
|
|
||||||
<param name="image_width" value="640" />
|
|
||||||
<param name="image_height" value="360" />
|
|
||||||
</node>
|
|
||||||
</group>
|
|
||||||
</launch>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<launch>
|
|
||||||
<group ns="cameras">
|
|
||||||
<node name="main_navigation" pkg="cv_camera" type="cv_camera_node" output="screen" >
|
|
||||||
<param name="device_path" value="/dev/rover/camera_main_navigation" />
|
|
||||||
<param name="image_width" value="1280" />
|
|
||||||
<param name="image_height" value="720" />
|
|
||||||
</node>
|
|
||||||
</group>
|
|
||||||
</launch>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<launch>
|
|
||||||
<group ns="cameras">
|
|
||||||
<node name="undercarriage" pkg="usb_cam" type="usb_cam_node" output="screen" >
|
|
||||||
<param name="video_device" value="/dev/rover/camera_undercarriage" />
|
|
||||||
<param name="image_width" value="640" />
|
|
||||||
<param name="image_height" value="360" />
|
|
||||||
<param name="pixel_format" value="mjpeg" />
|
|
||||||
<param name="camera_frame_id" value="usb_cam1" />
|
|
||||||
<param name="io_method" value="mmap"/>
|
|
||||||
</node>
|
|
||||||
</group>
|
|
||||||
</launch>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<launch>
|
|
||||||
<group ns="cameras">
|
|
||||||
<node name="undercarriage" pkg="usb_cam" type="usb_cam_node" output="screen" >
|
|
||||||
<param name="video_device" value="/dev/rover/camera_undercarriage" />
|
|
||||||
<param name="image_width" value="1280" />
|
|
||||||
<param name="image_height" value="720" />
|
|
||||||
<param name="pixel_format" value="mjpeg" />
|
|
||||||
<param name="camera_frame_id" value="usb_cam1" />
|
|
||||||
<param name="io_method" value="mmap"/>
|
|
||||||
</node>
|
|
||||||
</group>
|
|
||||||
</launch>
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<package format="2">
|
|
||||||
<name>rover_cameras</name>
|
|
||||||
<version>0.0.0</version>
|
|
||||||
<description>The rover_cameras package</description>
|
|
||||||
|
|
||||||
<!-- One maintainer tag required, multiple allowed, one person per tag -->
|
|
||||||
<!-- Example: -->
|
|
||||||
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
|
|
||||||
<maintainer email="nvidia@todo.todo">nvidia</maintainer>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- One license tag required, multiple allowed, one license per tag -->
|
|
||||||
<!-- Commonly used license strings: -->
|
|
||||||
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
|
|
||||||
<license>TODO</license>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Url tags are optional, but multiple are allowed, one per tag -->
|
|
||||||
<!-- Optional attribute type can be: website, bugtracker, or repository -->
|
|
||||||
<!-- Example: -->
|
|
||||||
<!-- <url type="website">http://wiki.ros.org/rover_cameras</url> -->
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Author tags are optional, multiple are allowed, one per tag -->
|
|
||||||
<!-- Authors do not have to be maintainers, but could be -->
|
|
||||||
<!-- Example: -->
|
|
||||||
<!-- <author email="jane.doe@example.com">Jane Doe</author> -->
|
|
||||||
|
|
||||||
|
|
||||||
<!-- The *depend tags are used to specify dependencies -->
|
|
||||||
<!-- Dependencies can be catkin packages or system dependencies -->
|
|
||||||
<!-- Examples: -->
|
|
||||||
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
|
|
||||||
<!-- <depend>roscpp</depend> -->
|
|
||||||
<!-- Note that this is equivalent to the following: -->
|
|
||||||
<!-- <build_depend>roscpp</build_depend> -->
|
|
||||||
<!-- <exec_depend>roscpp</exec_depend> -->
|
|
||||||
<!-- Use build_depend for packages you need at compile time: -->
|
|
||||||
<!-- <build_depend>message_generation</build_depend> -->
|
|
||||||
<!-- Use build_export_depend for packages you need in order to build against this package: -->
|
|
||||||
<!-- <build_export_depend>message_generation</build_export_depend> -->
|
|
||||||
<!-- Use buildtool_depend for build tool packages: -->
|
|
||||||
<!-- <buildtool_depend>catkin</buildtool_depend> -->
|
|
||||||
<!-- Use exec_depend for packages you need at runtime: -->
|
|
||||||
<!-- <exec_depend>message_runtime</exec_depend> -->
|
|
||||||
<!-- Use test_depend for packages you need only for testing: -->
|
|
||||||
<!-- <test_depend>gtest</test_depend> -->
|
|
||||||
<!-- Use doc_depend for packages you need only for building documentation: -->
|
|
||||||
<!-- <doc_depend>doxygen</doc_depend> -->
|
|
||||||
<buildtool_depend>catkin</buildtool_depend>
|
|
||||||
<build_depend>rospy</build_depend>
|
|
||||||
<build_export_depend>rospy</build_export_depend>
|
|
||||||
<exec_depend>rospy</exec_depend>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- The export tag contains other, unspecified, tags -->
|
|
||||||
<export>
|
|
||||||
<!-- Other tools can request additional information be placed here -->
|
|
||||||
|
|
||||||
</export>
|
|
||||||
</package>
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 2.8)
|
|
||||||
project(image_transport_tutorial)
|
|
||||||
|
|
||||||
find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport message_generation sensor_msgs)
|
|
||||||
|
|
||||||
# add the resized image message
|
|
||||||
add_message_files(DIRECTORY msg
|
|
||||||
FILES ResizedImage.msg
|
|
||||||
)
|
|
||||||
generate_messages(DEPENDENCIES sensor_msgs)
|
|
||||||
|
|
||||||
catkin_package(CATKIN_DEPENDS cv_bridge image_transport message_runtime sensor_msgs)
|
|
||||||
|
|
||||||
find_package(OpenCV)
|
|
||||||
|
|
||||||
include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
# add the publisher example
|
|
||||||
add_executable(my_publisher src/my_publisher.cpp)
|
|
||||||
add_dependencies(my_publisher ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS})
|
|
||||||
target_link_libraries(my_publisher ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
|
|
||||||
|
|
||||||
# add the subscriber example
|
|
||||||
#add_executable(my_subscriber src/my_subscriber.cpp)
|
|
||||||
#add_dependencies(my_subscriber ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS})
|
|
||||||
#target_link_libraries(my_subscriber ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
|
|
||||||
|
|
||||||
# add the plugin example
|
|
||||||
#add_library(resized_publisher src/manifest.cpp src/resized_publisher.cpp src/resized_subscriber.cpp)
|
|
||||||
#add_dependencies(resized_publisher ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS})
|
|
||||||
#target_link_libraries(resized_publisher ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
|
|
||||||
|
|
||||||
|
|
||||||
# Mark executables and/or libraries for installation
|
|
||||||
install(TARGETS my_publisher
|
|
||||||
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
||||||
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
||||||
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
|
|
||||||
)
|
|
||||||
|
|
||||||
#install(FILES resized_plugins.xml
|
|
||||||
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
|
|
||||||
#)
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#include <image_transport/simple_publisher_plugin.h>
|
|
||||||
#include <image_transport_tutorial/ResizedImage.h>
|
|
||||||
|
|
||||||
class ResizedPublisher : public image_transport::SimplePublisherPlugin<image_transport_tutorial::ResizedImage>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual std::string getTransportName() const
|
|
||||||
{
|
|
||||||
return "resized";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void publish(const sensor_msgs::Image& message,
|
|
||||||
const PublishFn& publish_fn) const;
|
|
||||||
};
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#include <image_transport/simple_subscriber_plugin.h>
|
|
||||||
#include <image_transport_tutorial/ResizedImage.h>
|
|
||||||
|
|
||||||
class ResizedSubscriber : public image_transport::SimpleSubscriberPlugin<image_transport_tutorial::ResizedImage>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~ResizedSubscriber() {}
|
|
||||||
|
|
||||||
virtual std::string getTransportName() const
|
|
||||||
{
|
|
||||||
return "resized";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void internalCallback(const typename image_transport_tutorial::ResizedImage::ConstPtr& message,
|
|
||||||
const Callback& user_cb);
|
|
||||||
};
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
uint32 original_height
|
|
||||||
uint32 original_width
|
|
||||||
sensor_msgs/Image image
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<library path="lib/libresized_image_transport">
|
|
||||||
<class name="resized_pub" type="ResizedPublisher" base_class_type="image_transport::PublisherPlugin">
|
|
||||||
<description>
|
|
||||||
This plugin publishes a decimated version of the image.
|
|
||||||
</description>
|
|
||||||
</class>
|
|
||||||
|
|
||||||
<class name="resized_sub" type="ResizedSubscriber" base_class_type="image_transport::SubscriberPlugin">
|
|
||||||
<description>
|
|
||||||
This plugin rescales a decimated image to its original size.
|
|
||||||
</description>
|
|
||||||
</class>
|
|
||||||
</library>
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#include <pluginlib/class_list_macros.h>
|
|
||||||
#include <image_transport_tutorial/resized_publisher.h>
|
|
||||||
#include <image_transport_tutorial/resized_subscriber.h>
|
|
||||||
|
|
||||||
PLUGINLIB_EXPORT_CLASS(ResizedPublisher, image_transport::PublisherPlugin)
|
|
||||||
|
|
||||||
PLUGINLIB_EXPORT_CLASS(ResizedSubscriber, image_transport::SubscriberPlugin)
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#include <ros/ros.h>
|
|
||||||
#include <image_transport/image_transport.h>
|
|
||||||
#include <opencv2/highgui/highgui.hpp>
|
|
||||||
#include <cv_bridge/cv_bridge.h>
|
|
||||||
|
|
||||||
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
|
|
||||||
cv::waitKey(10);
|
|
||||||
}
|
|
||||||
catch (cv_bridge::Exception& e)
|
|
||||||
{
|
|
||||||
ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
ros::init(argc, argv, "image_listener");
|
|
||||||
ros::NodeHandle nh;
|
|
||||||
cv::namedWindow("view");
|
|
||||||
cv::startWindowThread();
|
|
||||||
image_transport::ImageTransport it(nh);
|
|
||||||
image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback);
|
|
||||||
ros::spin();
|
|
||||||
cv::destroyWindow("view");
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#include <image_transport_tutorial/resized_publisher.h>
|
|
||||||
#include <opencv2/imgproc/imgproc.hpp>
|
|
||||||
#include <cv_bridge/cv_bridge.h>
|
|
||||||
|
|
||||||
void ResizedPublisher::publish(const sensor_msgs::Image& message,
|
|
||||||
const PublishFn& publish_fn) const
|
|
||||||
{
|
|
||||||
cv::Mat cv_image;
|
|
||||||
boost::shared_ptr<void const> tracked_object;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
cv_image = cv_bridge::toCvShare(message, tracked_object, message.encoding)->image;
|
|
||||||
}
|
|
||||||
catch (cv::Exception &e)
|
|
||||||
{
|
|
||||||
ROS_ERROR("Could not convert from '%s' to '%s'.", message.encoding.c_str(), message.encoding.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve subsampling factor from the parameter server
|
|
||||||
double subsampling_factor;
|
|
||||||
std::string param_name;
|
|
||||||
nh().param<double>("resized_image_transport_subsampling_factor", subsampling_factor, 2.0);
|
|
||||||
|
|
||||||
// Rescale image
|
|
||||||
int new_width = cv_image.cols / subsampling_factor + 0.5;
|
|
||||||
int new_height = cv_image.rows / subsampling_factor + 0.5;
|
|
||||||
cv::Mat buffer;
|
|
||||||
cv::resize(cv_image, buffer, cv::Size(new_width, new_height));
|
|
||||||
|
|
||||||
// Set up ResizedImage and publish
|
|
||||||
image_transport_tutorial::ResizedImage resized_image;
|
|
||||||
resized_image.original_height = cv_image.rows;
|
|
||||||
resized_image.original_width = cv_image.cols;
|
|
||||||
resized_image.image = *(cv_bridge::CvImage(message.header, "bgr8", cv_image).toImageMsg());
|
|
||||||
publish_fn(resized_image);
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#include <image_transport_tutorial/resized_subscriber.h>
|
|
||||||
#include <cv_bridge/cv_bridge.h>
|
|
||||||
#include <opencv2/imgproc/imgproc.hpp>
|
|
||||||
|
|
||||||
void ResizedSubscriber::internalCallback(const image_transport_tutorial::ResizedImage::ConstPtr& msg,
|
|
||||||
const Callback& user_cb)
|
|
||||||
{
|
|
||||||
// This is only for optimization, not to copy the image
|
|
||||||
boost::shared_ptr<void const> tracked_object_tmp;
|
|
||||||
cv::Mat img_rsz = cv_bridge::toCvShare(msg->image, tracked_object_tmp)->image;
|
|
||||||
// Resize the image to its original size
|
|
||||||
cv::Mat img_restored;
|
|
||||||
cv::resize(img_rsz, img_restored, cv::Size(msg->original_width, msg->original_height));
|
|
||||||
|
|
||||||
// Call the user callback with the restored image
|
|
||||||
cv_bridge::CvImage cv_img(msg->image.header, msg->image.encoding, img_restored);
|
|
||||||
user_cb(cv_img.toImageMsg());
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user