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


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

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

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

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

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.

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

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.




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

Love podcasts or audiobooks? Learn on the go with our new app.


Resume Screening with Natural Language Processing in Python

Demystifying a Typical Search Problem Using Inverted Index

4 steps to create a perfect roadmap for your project

The Newbie’s Guide to Using The useReducer Hook in React

Rhythm Quest Devlog 20 — Speed Zones

Specialized collections for Enums

Golang — Basic & Detailed Introduction!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanush B

Dhanush B

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

More from Medium

How to Install and configure Qt5 manually on Ubuntu 18.04

Error Diffusion Dithering — Stucki with Python

Cobra Pose Detection using Mediapipe and Python

Pop OS (Ubuntu): Install DarkNet for YOLOv4 Object Detection with GPU and OpenCV support