Skip to content

Commit

Permalink
Port traffic light visualization (autowarefoundation#121)
Browse files Browse the repository at this point in the history
* Port

Signed-off-by: Servando German Serrano <servando.german.serrano@linaro.org>

* Fix package.xml

Signed-off-by: Servando German Serrano <servando.german.serrano@linaro.org>

* Removed unused mutex

Signed-off-by: Servando German Serrano <servando.german.serrano@linaro.org>
  • Loading branch information
sgermanserrano authored Dec 8, 2020
1 parent aca4a60 commit f326b4f
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 217 deletions.
Original file line number Diff line number Diff line change
@@ -1,85 +1,41 @@
cmake_minimum_required(VERSION 3.0.2)
cmake_minimum_required(VERSION 3.5)
project(traffic_light_visualization)

add_compile_options(-std=c++14)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
add_compile_options(-Wno-unused-parameter)
endif()

find_package(catkin REQUIRED COMPONENTS
autoware_perception_msgs
cv_bridge
image_transport
message_filters
roscpp
sensor_msgs
nodelet
)
find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

find_package(OpenCV REQUIRED)


catkin_package(
CATKIN_DEPENDS
)

include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)

###########
## Build ##
###########

add_library(traffic_light_roi_visualizer_nodelet SHARED
ament_auto_add_library(traffic_light_roi_visualizer_nodelet SHARED
src/nodelet.cpp
)

add_dependencies(traffic_light_roi_visualizer_nodelet
${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS}
)

target_link_libraries(traffic_light_roi_visualizer_nodelet
${catkin_LIBRARIES}
${OpenCV_LIBRARIES}
)

add_executable(traffic_light_roi_visualizer_node
src/node.cpp
)

add_dependencies(traffic_light_roi_visualizer_node
${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS}
)

target_link_libraries(traffic_light_roi_visualizer_node
traffic_light_roi_visualizer_nodelet
${catkin_LIBRARIES}
${OpenCV_LIBRARIES}
rclcpp_components_register_node(traffic_light_roi_visualizer_nodelet
PLUGIN "traffic_light::TrafficLightRoiVisualizerNodelet"
EXECUTABLE traffic_light_visualization_node
)

#############
## Install ##
#############

install(
TARGETS
traffic_light_roi_visualizer_node
traffic_light_roi_visualizer_nodelet
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(
FILES
traffic_light_roi_visualizer.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

install(
DIRECTORY
launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
ament_auto_package(
INSTALL_TO_SHARE
launch
)
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "ros/ros.h"

#include "image_transport/image_transport.h"
#include "image_transport/subscriber_filter.h"
#include "autoware_perception_msgs/TrafficLightRoiArray.h"
#include "rclcpp/rclcpp.hpp"

#include "image_transport/image_transport.hpp"
#include "image_transport/subscriber_filter.hpp"
#include "autoware_perception_msgs/msg/traffic_light_roi_array.hpp"
#include "message_filters/subscriber.h"
#include "message_filters/sync_policies/approximate_time.h"
#include "message_filters/synchronizer.h"
#include "sensor_msgs/Image.h"
#include "nodelet/nodelet.h"
#include "pluginlib/class_list_macros.h"
#include "sensor_msgs/msg/image.hpp"

#include "cv_bridge/cv_bridge.h"
#include "opencv2/imgproc/imgproc_c.h"
Expand All @@ -33,48 +32,46 @@

namespace traffic_light
{
class TrafficLightRoiVisualizerNodelet : public nodelet::Nodelet
class TrafficLightRoiVisualizerNodelet : public rclcpp::Node
{
public:
virtual void onInit();
TrafficLightRoiVisualizerNodelet(const rclcpp::NodeOptions & options);
void connectCb();

void imageRoiCallback(
const sensor_msgs::ImageConstPtr & input_image_msg,
const autoware_perception_msgs::TrafficLightRoiArray::ConstPtr & input_tl_roi_msg);
const sensor_msgs::msg::Image::ConstSharedPtr & input_image_msg,
const autoware_perception_msgs::msg::TrafficLightRoiArray::ConstSharedPtr & input_tl_roi_msg);

void imageRoughRoiCallback(
const sensor_msgs::ImageConstPtr & input_image_msg,
const autoware_perception_msgs::TrafficLightRoiArrayConstPtr & input_tl_roi_msg,
const autoware_perception_msgs::TrafficLightRoiArrayConstPtr & input_tl_rough_roi_msg);
const sensor_msgs::msg::Image::ConstSharedPtr & input_image_msg,
const autoware_perception_msgs::msg::TrafficLightRoiArray::ConstSharedPtr & input_tl_roi_msg,
const autoware_perception_msgs::msg::TrafficLightRoiArray::ConstSharedPtr & input_tl_rough_roi_msg);

private:
bool createRect(
cv::Mat& image,
const autoware_perception_msgs::TrafficLightRoi& tl_roi,
const autoware_perception_msgs::msg::TrafficLightRoi& tl_roi,
const cv::Scalar& color);

ros::NodeHandle nh_, pnh_;
std::shared_ptr<image_transport::ImageTransport> image_transport_;
rclcpp::TimerBase::SharedPtr timer_;
image_transport::SubscriberFilter image_sub_;
message_filters::Subscriber<autoware_perception_msgs::TrafficLightRoiArray> roi_sub_;
message_filters::Subscriber<autoware_perception_msgs::TrafficLightRoiArray> rough_roi_sub_;
message_filters::Subscriber<autoware_perception_msgs::msg::TrafficLightRoiArray> roi_sub_;
message_filters::Subscriber<autoware_perception_msgs::msg::TrafficLightRoiArray> rough_roi_sub_;
image_transport::Publisher image_pub_;
typedef message_filters::sync_policies::ApproximateTime<
sensor_msgs::Image, autoware_perception_msgs::TrafficLightRoiArray>
sensor_msgs::msg::Image, autoware_perception_msgs::msg::TrafficLightRoiArray>
SyncPolicy;
typedef message_filters::Synchronizer<SyncPolicy> Sync;
std::shared_ptr<Sync> sync_;

typedef message_filters::sync_policies::ApproximateTime<
sensor_msgs::Image,
autoware_perception_msgs::TrafficLightRoiArray,
autoware_perception_msgs::TrafficLightRoiArray>
sensor_msgs::msg::Image,
autoware_perception_msgs::msg::TrafficLightRoiArray,
autoware_perception_msgs::msg::TrafficLightRoiArray>
SyncPolicyWithRoughRoi;
typedef message_filters::Synchronizer<SyncPolicyWithRoughRoi> SyncWithRoughRoi;
std::shared_ptr<SyncWithRoughRoi> sync_with_rough_roi_;

std::mutex connect_mutex_;
bool enable_fine_detection_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<arg name="enable_fine_detection" default="false"/>
<arg name="manager" default="traffic_light_recognition_nodelet_manager"/>

<node pkg="nodelet" type="nodelet" name="traffic_light_roi_visualizer" args="load traffic_light/traffic_light_roi_visualizer $(arg manager)">
<remap from="~input/image" to="$(arg input/image)"/>
<remap from="~input/rois" to="$(arg input/rois)"/>
<remap from="~input/rough/rois" to="$(arg input/rough/rois)"/>
<remap from="~output/image" to="$(arg output/image)"/>
<param name="enable_fine_detection" value="$(arg enable_fine_detection)"/>
<node pkg="traffic_light_visualization" exec="traffic_light_visualization_node" name="traffic_light_visualization">
<remap from="input/image" to="$(var input/image)"/>
<remap from="input/rois" to="$(var input/rois)"/>
<remap from="input/rough/rois" to="$(var input/rough/rois)"/>
<remap from="output/image" to="$(var output/image)"/>
<param name="enable_fine_detection" value="$(var enable_fine_detection)"/>
</node>
</launch>
68 changes: 10 additions & 58 deletions perception/util/visualizer/traffic_light_visualization/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,20 @@
<description>The traffic_light_visualization package</description>

<maintainer email="yukihiro.saito@tier4.jp">Yukihiro Saito</maintainer>
<license>Apache2</license>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>


<!-- 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/traffic_light_visualization</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>autoware_perception_msgs</build_depend>
<build_depend>cv_bridge</build_depend>
<build_depend>image_transport</build_depend>
<build_depend>message_filters</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>nodelet</build_depend>
<build_export_depend>autoware_perception_msgs</build_export_depend>
<build_export_depend>cv_bridge</build_export_depend>
<build_export_depend>image_transport</build_export_depend>
<build_export_depend>message_filters</build_export_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>sensor_msgs</build_export_depend>
<build_export_depend>nodelet</build_export_depend>
<exec_depend>autoware_perception_msgs</exec_depend>
<exec_depend>cv_bridge</exec_depend>
<exec_depend>image_transport</exec_depend>
<exec_depend>message_filters</exec_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>nodelet</exec_depend>

<depend>autoware_perception_msgs</depend>
<depend>cv_bridge</depend>
<depend>image_transport</depend>
<depend>message_filters</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>sensor_msgs</depend>

<!-- The export tag contains other, unspecified, tags -->
<export>
<nodelet plugin="${prefix}/traffic_light_roi_visualizer.xml" />
<build_type>ament_cmake</build_type>
</export>
</package>

This file was deleted.

Loading

0 comments on commit f326b4f

Please sign in to comment.