-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Image transport tutorial (#197)"
This reverts commit 8cef3db.
- Loading branch information
1 parent
8cef3db
commit aff47b5
Showing
22 changed files
with
224 additions
and
753 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,43 @@ | ||
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 my_subscriber resized_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} | ||
) |
15 changes: 15 additions & 0 deletions
15
image_transport/tutorial/include/image_transport_tutorial/resized_publisher.hpp
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 @@ | ||
#include <image_transport/simple_publisher_plugin.hpp> | ||
#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; | ||
}; |
26 changes: 26 additions & 0 deletions
26
image_transport/tutorial/include/image_transport_tutorial/resized_subscriber.hpp
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,26 @@ | ||
#include <image_transport/simple_subscriber_plugin.hpp> | ||
#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"; | ||
} | ||
|
||
void subscribeImpl( | ||
rclcpp::Node * node, | ||
const std::string & base_topic, | ||
const Callback & callback, | ||
rmw_qos_profile_t custom_qos, | ||
rclcpp::SubscriptionOptions options) override | ||
{ | ||
this->subscribeImplWithOptions(node, base_topic, callback, custom_qos, options); | ||
} | ||
protected: | ||
virtual void internalCallback(const typename image_transport_tutorial::ResizedImage::ConstPtr& message, | ||
const Callback& user_cb); | ||
}; |
File renamed without changes.
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,26 @@ | ||
<package> | ||
<name>image_transport_tutorial</name> | ||
<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> | ||
<author>Vincent Rabaud</author> | ||
<maintainer email="[email protected]">Vincent Rabaud</maintainer> | ||
<license>Apache 2.0</license> | ||
|
||
<build_depend>cv_bridge</build_depend> | ||
<build_depend>image_transport</build_depend> | ||
<build_depend>message_generation</build_depend> | ||
<build_depend>opencv2</build_depend> | ||
<build_depend>sensor_msgs</build_depend> | ||
|
||
<run_depend>cv_bridge</run_depend> | ||
<run_depend>image_transport</run_depend> | ||
<run_depend>message_runtime</run_depend> | ||
<run_depend>opencv2</run_depend> | ||
<run_depend>sensor_msgs</run_depend> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
|
||
<export> | ||
<image_transport plugin="${prefix}/resized_plugins.xml"/> | ||
</export> | ||
</package> |
File renamed without changes.
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,7 @@ | ||
#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) |
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 @@ | ||
#include <cv_bridge/cv_bridge.h> | ||
#include <image_transport/image_transport.hpp> | ||
#include <opencv2/highgui/highgui.hpp> | ||
#include <ros/ros.h> | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
ros::init(argc, argv, "image_publisher"); | ||
ros::NodeHandle nh; | ||
image_transport::ImageTransport it(nh); | ||
image_transport::Publisher pub = it.advertise("camera/image", 1); | ||
|
||
cv::Mat image = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR); | ||
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg(); | ||
|
||
ros::Rate loop_rate(5); | ||
while (nh.ok()) { | ||
pub.publish(msg); | ||
ros::spinOnce(); | ||
loop_rate.sleep(); | ||
} | ||
} | ||
|
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,29 @@ | ||
#include <cv_bridge/cv_bridge.h> | ||
#include <image_transport/image_transport.hpp> | ||
#include <opencv2/highgui/highgui.hpp> | ||
#include <ros/ros.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"); | ||
} |
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,37 @@ | ||
#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); | ||
} |
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,18 @@ | ||
#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()); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.