Imagery & Cameras - qutas/info GitHub Wiki
Image Formats
Cameras
Calibration in ROS (Monocular)
How to Calibrate a Monocular Camera
Useful Applications
guvcview
guvcview is a standardized camera interfacing application and is a great first step in making sure a uvc camera is functioning correctly.
ROS Interfaces
OpenCV
OpenCV is an all-in-one general purpose image processing library.
sudo apt install ros-kinetic-vision-opencv
Image Transport
Image Transport allows for smart and convenient handling of image streams and compressed images.
sudo apt install ros-kinetic-image-transport ros-kinetic-image-transport-plugins
Image Visualization
The RQT Image View Plugin allows for image streams to be viewed in RQT.
sudo apt install ros-kinetic-rqt-image-view
Camera Interfaces
TODO: Put this in a comparison table
- uvc_camera - Unsupported
- libuvc_camera - Unsupported
- usb_cam - Supports the widest range of cameras
- cv_camera
- video_stream_opencv - This is the best general purpose one to date
- raspicam_node - This is the only option for interfacing with the Raspberry Pi Camera
Exporting ROS Image Stream to Video
Setup
To export images to a video file, there are a few things that you will need to do first:
- Change directory to the same location as your
.bag
files - Download the topic2video.
wget https://gist.githubusercontent.com/pryre/8d6f44e18d52efb616f64403de0838ef/raw/ed6b8851e5ebb4e6e7bfa7289f53a61733733211/topic2video.py
- Figure out the framerate your video was running at (use
rostopic hz /webcam/image_raw
, but for your camera/image topic).
Note that you can see more information on the tool by running the command:
python topic2video.py --help
Exporting a Live Video
Run the following command and press 'CTRL+C' when you want to end the recording:
python topic2video.py /webcam/image_raw -r 30
Where 30
is the framerate of your camera (used to encode the exported video at the correct rate).
Exporting from rosbag
Run the following command and wait for it to finish:
python topic2video.py /webcam/image_raw -r 30 -b recording.bag
Where 30
is the framerate of your camera (used to encode the exported video at the correct rate) and recording.bag
is the filename of the bag file you want to use.
Exporting rosbag Images
Setup
To export images to a video file, there are a few things that you will need to do first:
- Create a working directory folder:
mkdir /tmp/video_export
- Download the export script to the working folder. Note that this will export
.png
compressed images and dump them into your the directory:
cd /tmp/video_export
wget https://raw.githubusercontent.com/qutas/info/master/Scripts/image_saver.py
- Figure out the framerate your video was running at (use
rostopic hz /webcam/image_raw/compressed
, but for your camera/image topic)
Image Extraction
To do the actual export process, open three different terminals and run the following commands:
- Terminal 1:
roscore
- Terminal 2:
cd /tmp/video_export
python image_saver.py /camera_name/image_topic
# OR: python image_saver.py /camera_name/image_topic/compressed
- Terminal 3 (replace
BAG_FILE_NAME
as with your bag file recording):
rosbag play BAG_FILE_NAME
Once the bag file recording is complete, the image files should now be saved in /tmp/video_export
Recombine the images into a video (optional)
The final step is to recombine all the images into a video file. To do this, we can use the tool ffmpeg.
The only trick here is that our image filenames are saved using their timestamps, so they may will need to be renamed such that ffmpeg can easily accept them:
cd /tmp/video_export
ls -v *.png | gawk 'BEGIN{ a=1 }{ printf "mv %s %06d.png\n", $0, a++ }' | bash
Finally, we can combine our images into a video (make sure to enter the framerate of your video in FRAMERATE
):
ffmpeg -r FRAMERATE -i %06d.png -c:v libx264 -vf fps=30 -pix_fmt yuv420p -crf 18 out.mp4
Your exported video should now be compiled!