Using OpenCV with Gazebo in Robot Operating System (ROS) — Part 0 — Getting everything set up

Dhanush B
4 min readFeb 12, 2021

Intro

This will be a three part series, in which I’ll help you to use OpenCV with Gazebo in ROS (Robot Operating System)

  • Part 0 — Getting everything set up
  • Part 1 — Display real-time video feed of 2D camera in gazebo
  • Part 2 — Read and decode a QR Code present in Gazebo with pyzbar library

Alrighty! Let’s get started with Part 0. Oh wait. Why did I start with Part 0 instead of Part 1 tho? Coz I wanted to flex on ‘em non-CS folks and confuse them xD

Getting things in order

1. Installing Gazebo

Assuming you have ROS and Gazebo installed, I’ll move forward with this tutorial. If you’re not sure if Gazebo is installed, type gazebo in terminal. It should open a window like this

An empty Gazebo world

If you don’t get a screen like this, follow the official tutorial in this link to install gazebo on your machine

2. Installing OpenCV

Once you’re done with that, you gotta install OpenCV. To do that run the following command in terminal

$ sudo apt-get install libopencv-dev python-opencv

3. Installing pyzbar

Up next, we have to install a python library called pyzbar that allows us to scan barcodes and QR codes using 2D camera. We will be using pyzbar in part 2 of this series.

To install, run this command in terminal.

$ pip install pyzbar

If you haven’t installed pip on you machine, run this command in terminal.

$ sudo apt install python-pip

4. Installing cv_bridge

Finally, to install cv_bridge run these commands separately in terminal.

$ sudo apt-get install ros-$ROS_DISTRO-vision-opencv$ sudo apt-get install ros-$ROS_DISTRO-cv-bridge

We’ll see more about this package in the upcoming section.

5. Using my customized ROS package

All the scripts, models and world files used in this series are available in my repository as a ROS Package.

Link to GitHub Repo

Alternatively, you can clone it to your PC by running this command in src folder of your workspace(for example, catkin_ws/src)

$ git clone https://github.com/dhanuzch/pkg_cv_ros_tutorial_by_dhanuzch.git

And then compile the package by running catkin build or catkin_make , This depends on which build system you use. I personally prefercatkin build over catkin_make because it has additional functionalities and really useful tools that catkin_makedoesn’t offer.

To learn more about the differences between these two

Intro to cv_bridge

Most of you reading this might know what ROS is and how fast the number of ROS powered robots is growing day by day. Nowadays, ROS is being used in NASA’s Rovers, vaccuum cleaners and even in boring industrial robots :p

And robot vision is a key aspect in Robotics, Many robots use 3D depth sensors and other sensors such as LIDARs and RADARs to perceive the world. Similiarly 2D cameras are used in robots for various objectives and tasks. Using 2D cameras has its own set of advantages that other sensors simply can’t provide.

OpenCV is a tool that allows us to process images from those cameras and it enables us to recognize faces, objects and texts and finally what we will be doing in this tutorial series - decode QR Codes. There are so many applications to openCV, just a simple google search will give you an idea of the features and functionalities of openCV.

cv_bridge allows us to use those functionalities and features in our robots that run on ROS. In other words, it bridges the gap between ROS and openCV, allowing us to use and explore a whole array of features related to robot vision.

--

--

Dhanush B

Hey! connect with me if you wanna talk about robotics, tech, philosophy and history.