Skip to content

Commit

Permalink
added video_stream_opencv package for use with the ar tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurenhut committed Nov 22, 2017
1 parent f7b9a30 commit 4fd3da0
Show file tree
Hide file tree
Showing 15 changed files with 645 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/video_stream_opencv/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package video_stream_opencv
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1.0.2 (2016-11-14)
------------------

1.0.1 (2016-11-14)
------------------
* Releasable version
* Contributors: Sammy Pfeiffer, Stefano Probst, Wiebe Van Ranst
36 changes: 36 additions & 0 deletions src/video_stream_opencv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 2.8.3)
project(video_stream_opencv)

find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
cv_bridge
image_transport
camera_info_manager
sensor_msgs
)


find_package(OpenCV)

catkin_package()

include_directories(
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)

add_executable(video_stream src/video_stream.cpp)
target_link_libraries(video_stream ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})

install(TARGETS video_stream
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

install(PROGRAMS
scripts/test_video_resource.py

DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
64 changes: 64 additions & 0 deletions src/video_stream_opencv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
A package to view video streams based on the [OpenCV VideoCapture module](http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture), easy way to publish on a ROS Image topic (including camera info) usb cams, ethernet cameras, video streams or video files. It also supports flipping of images.

![Screenshot of the plugin working with a webcam, video stream and video file](https://raw.githubusercontent.com/pal-robotics/video_stream_opencv/master/screenshot_usage.png)

Example usages in launch folder (**only the argument `video_stream_provider` is mandatory**):

```xml
<launch>
<!-- launch video stream -->
<include file="$(find video_stream_opencv)/launch/camera.launch" >
<!-- node name and ros graph name -->
<arg name="camera_name" value="webcam" />
<!-- means video device 0, /dev/video0 -->
<arg name="video_stream_provider" value="0" />
<!-- throttling the querying of frames to -->
<arg name="fps" value="30" />
<!-- setting frame_id -->
<arg name="frame_id" value="webcam" />
<!-- camera info loading, take care as it needs the "file:///" at the start , e.g.:
"file:///$(find your_camera_package)/config/your_camera.yaml" -->
<arg name="camera_info_url" value="" />
<!-- flip the image horizontally (mirror it) -->
<arg name="flip_horizontal" value="false" />
<!-- flip the image vertically -->
<arg name="flip_vertical" value="false" />
<!-- force a width and height, 0 means no forcing -->
<arg name="width" value="640"/>
<arg name="height" value="480"/>
<!-- visualize on an image_view window the stream generated -->
<arg name="visualize" value="true" />
</include>
</launch>
```

Based on the ROS [tutorial to convert opencv images to ROS messages](http://wiki.ros.org/image_transport/Tutorials/PublishingImages).

===

You can use any input that OpenCV on your system accepts, e.g.:

* Video devices that appear in linux as /dev/videoX, e.g.: USB webcams appearing as /dev/video0

* Video streamings, e.g.: rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov

* Video files, anything you can play, e.g.: myvideo.avi

* Etc.

===

In the scripts folder you'll find `test_video_resource.py` which you can use to test if your system
installation can use this node to open your video stream (not using any ROS). Just do any of those:

./test_video_resource.py 0
./test_video_resource.py rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov
./test_video_resource.py /home/youruser/myvideo.mkv

And you'll see an output like:

Trying to open resource: /dev/video0
Correctly opened resource, starting to show feed.

With an OpenCV image show window showing the stream (which should close when pressing ESC, or Control+C the shell).

20 changes: 20 additions & 0 deletions src/video_stream_opencv/config/test_calibration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
image_width: 1280
image_height: 960
camera_name: "0800461000822014"
camera_matrix:
rows: 3
cols: 3
data: [2302.59, 0, 610.756, 0, 2309.46, 506.539, 0, 0, 1]
distortion_model: plumb_bob
distortion_coefficients:
rows: 1
cols: 5
data: [-0.225495, -0.363048, -0.000477994, -0.000132753, 0]
rectification_matrix:
rows: 3
cols: 3
data: [1, 0, 0, 0, 1, 0, 0, 0, 1]
projection_matrix:
rows: 3
cols: 4
data: [2302.59, 0, 610.756, 0, 0, 2309.46, 506.539, 0, 0, 0, 1, 0]
44 changes: 44 additions & 0 deletions src/video_stream_opencv/launch/camera.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<launch>
<arg name="camera_name" default="camera" />
<!-- video_stream_provider can be a number as a video device or a url of a video stream -->
<arg name="video_stream_provider" default="0" />
<!-- frames per second to query the camera for -->
<arg name="fps" default="30" />
<!-- frame_id for the camera -->
<arg name="frame_id" default="$(arg camera_name)" />
<!-- By default, calibrations are stored to file://${ROS_HOME}/camera_info/${NAME}.yaml
To use your own fill this arg with the corresponding url, e.g.:
"file:///$(find your_camera_package)/config/your_camera.yaml" -->
<arg name="camera_info_url" default="" />
<!-- flip the image horizontally (mirror it) -->
<arg name="flip_horizontal" default="false" />
<!-- flip the image vertically -->
<arg name="flip_vertical" default="false" />
<!-- force width and height, 0 means no forcing -->
<arg name="width" default="0"/>
<arg name="height" default="0"/>
<!-- if show a image_view window subscribed to the generated stream -->
<arg name="visualize" default="false"/>


<!-- images will be published at /camera_name/image with the image transports plugins (e.g.: compressed) installed -->
<group ns="$(arg camera_name)">
<node pkg="video_stream_opencv" type="video_stream" name="$(arg camera_name)_stream" output="screen">
<remap from="camera" to="image_raw" />
<param name="camera_name" type="string" value="$(arg camera_name)" />
<param name="video_stream_provider" type="string" value="$(arg video_stream_provider)" />
<param name="fps" type="int" value="$(arg fps)" />
<param name="frame_id" type="string" value="$(arg frame_id)" />
<param name="camera_info_url" type="string" value="$(arg camera_info_url)" />
<param name="flip_horizontal" type="bool" value="$(arg flip_horizontal)" />
<param name="flip_vertical" type="bool" value="$(arg flip_vertical)" />
<param name="width" type="int" value="$(arg width)" />
<param name="height" type="int" value="$(arg height)" />
</node>

<node if="$(arg visualize)" name="$(arg camera_name)_image_view" pkg="image_view" type="image_view">
<remap from="image" to="image_raw" />
</node>
</group>

</launch>
22 changes: 22 additions & 0 deletions src/video_stream_opencv/launch/mjpg_stream.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<launch>
<!-- launch video stream -->
<include file="$(find video_stream_opencv)/launch/camera.launch" >
<!-- node name and ros graph name -->
<arg name="camera_name" value="axis_videocap" />
<!-- url of the video stream -->
<arg name="video_stream_provider" value="http://10.68.0.6/mjpg/video.mjpg" />
<!-- throttling the querying of frames to -->
<arg name="fps" value="30" />
<!-- setting frame_id -->
<arg name="frame_id" value="axis_optical_frame" />
<!-- camera info loading, take care as it needs the "file:///" at the start , e.g.:
"file:///$(find your_camera_package)/config/your_camera.yaml" -->
<arg name="camera_info_url" value="" />
<!-- flip the image horizontally (mirror it) -->
<arg name="flip_horizontal" value="false" />
<!-- flip the image vertically -->
<arg name="flip_vertical" value="false" />
<!-- visualize on an image_view window the stream generated -->
<arg name="visualize" value="false" />
</include>
</launch>
22 changes: 22 additions & 0 deletions src/video_stream_opencv/launch/rtsp_stream.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<launch>
<!-- launch video stream -->
<include file="$(find video_stream_opencv)/launch/camera.launch" >
<!-- node name and ros graph name -->
<arg name="camera_name" value="rtsp" />
<!-- url of the video stream -->
<arg name="video_stream_provider" value="rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov" />
<!-- throttling the querying of frames to -->
<arg name="fps" value="30" />
<!-- setting frame_id -->
<arg name="frame_id" value="rtsp_frame" />
<!-- camera info loading, take care as it needs the "file:///" at the start , e.g.:
"file:///$(find your_camera_package)/config/your_camera.yaml" -->
<arg name="camera_info_url" value="" />
<!-- flip the image horizontally (mirror it) -->
<arg name="flip_horizontal" value="false" />
<!-- flip the image vertically -->
<arg name="flip_vertical" value="false" />
<!-- visualize on an image_view window the stream generated -->
<arg name="visualize" value="true" />
</include>
</launch>
17 changes: 17 additions & 0 deletions src/video_stream_opencv/launch/test_camera_info.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<launch>
<!-- launch video stream -->
<include file="$(find video_stream_opencv)/launch/camera.launch" >
<!-- node name and ros graph name -->
<arg name="camera_name" value="rtsp" />
<!-- url of the video stream -->
<arg name="video_stream_provider" value="rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov" />
<!-- throttling the querying of frames to -->
<arg name="fps" value="30" />
<!-- setting frame_id -->
<arg name="frame_id" value="rtsp" />
<!-- camera info loading, take care as it needs the "file:///" at the start , e.g.:-->
<arg name="camera_info_url" value="file:///$(find video_stream_opencv)/config/test_calibration.yaml"/>
<!-- visualize on an image_view window the stream generated -->
<arg name="visualize" value="true" />
</include>
</launch>
22 changes: 22 additions & 0 deletions src/video_stream_opencv/launch/video_file.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<launch>
<!-- launch video stream -->
<include file="$(find video_stream_opencv)/launch/camera.launch" >
<!-- node name and ros graph name -->
<arg name="camera_name" value="videofile" />
<!-- full path to the video file -->
<arg name="video_stream_provider" value="/home/sampfeiffer/Videos/REEM_grasping.mp4" />
<!-- throttling the querying of frames to -->
<arg name="fps" value="30" />
<!-- setting frame_id -->
<arg name="frame_id" value="videofile_frame" />
<!-- camera info loading, take care as it needs the "file:///" at the start , e.g.:
"file:///$(find your_camera_package)/config/your_camera.yaml" -->
<arg name="camera_info_url" value="" />
<!-- flip the image horizontally (mirror it) -->
<arg name="flip_horizontal" value="false" />
<!-- flip the image vertically -->
<arg name="flip_vertical" value="false" />
<!-- visualize on an image_view window the stream generated -->
<arg name="visualize" value="true" />
</include>
</launch>
27 changes: 27 additions & 0 deletions src/video_stream_opencv/launch/webcam.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<launch>
<!-- launch video stream -->
<include file="$(find video_stream_opencv)/launch/camera.launch" >
<!-- node name and ros graph name -->
<arg name="camera_name" value="webcam" />
<!-- means video device 0, /dev/video0 -->
<arg name="video_stream_provider" value="0" />
<!-- throttling the querying of frames to -->
<arg name="fps" value="30" />
<!-- setting frame_id -->
<arg name="frame_id" value="webcam_optical_frame" />
<!-- camera info loading, take care as it needs the "file:///" at the start , e.g.:
"file:///$(find your_camera_package)/config/your_camera.yaml" -->
<arg name="camera_info_url" value="" />
<!-- flip the image horizontally (mirror it) -->
<arg name="flip_horizontal" value="false" />
<!-- flip the image vertically -->
<arg name="flip_vertical" value="false" />
<!-- force width and height, 0 means no forcing -->
<!--
<arg name="width" value="0"/>
<arg name="height" value="0"/>
-->
<!-- visualize on an image_view window the stream generated -->
<arg name="visualize" value="true" />
</include>
</launch>
36 changes: 36 additions & 0 deletions src/video_stream_opencv/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<package>
<name>video_stream_opencv</name>
<version>1.0.2</version>

<description>
The video_stream_opencv package contains a node to publish a video stream (the protocols that
opencv supports are supported, including rtsp, webcams on /dev/video and video files) in ROS image topics, it supports camera info and basic image flipping (horizontal, vertical or both) capabilities.
</description>

<maintainer email="[email protected]">Sammy Pfeiffer</maintainer>
<author>Sammy Pfeiffer</author>

<url type="website">http://www.ros.org/wiki/video_stream_opencv</url>
<url type="development">https://github.com/ros-drivers/video_stream_opencv</url>
<url type="bugtracker">https://github.com/ros-drivers/video_stream_opencv/issues</url>

<license>BSD</license>

<buildtool_depend>catkin</buildtool_depend>

<build_depend>cv_bridge</build_depend>
<build_depend>image_transport</build_depend>
<build_depend>camera_info_manager</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>sensor_msgs</build_depend>

<run_depend>cv_bridge</run_depend>
<run_depend>image_transport</run_depend>
<run_depend>camera_info_manager</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>sensor_msgs</run_depend>

</package>
Loading

0 comments on commit 4fd3da0

Please sign in to comment.