OpenCV for Shape Detection with RF Communication


Hey,

This was one of the first projects I ever did in BITS Goa. It’s not documented well, but it was truly a life changing experience for me. I got introduced to many concepts of C, OpenCV, Electronics Micro controllers like Arduino , RF interfacing, etc. This project sure formed a good base of what I am today. I had participated in an event “Catch me if you can”. The event’s main purpose was to find three bots with different shapes drawn over  them. Once identified, the bot had to catch it in real-time.

The different shapes, ie the circle, star and square denote the enemy bots while the multicoloured rectangle is my bot.

I used OpenCV 2.1 for vision, to detect different shapes using the function CvFitEllipse ( Installing OpenCV ). I threshed the Black colour of the image , passed that through the canny function, determined the shape of the object. Once the shape was recognised, I calculated the centroid of the image. The centroid would be the about centre of the bot. The lighting conditions were adjusted in such a way that it didn’t generate a lot of noise. I did not use any specific filters to filter out the noise in the image ( It was my first time with coding in C and using OpenCV! ). So once the approximate centroid for all the shaped bots was known, I would then save the co-ordinates. The co-ordinates for my bot were too calculated and saved. The problem statement directed to catch the bots in a specified order. So the distance between the enemy bot and my bot was calculated and  directions and distances were calculated and given to the bot via cheap radio communication! I used rf transmitter and receiver with an Arduino Duemilanove ( with ATMEGA328) :

These simple rf transmitters and receivers can be brought at any cheap local hardware store.

The transmitter was attached to my Linux box which was doing all the computation using OpenCV. All the decisions made by the computer were sent across to a receiver circuit put up on my moving robot.

This was the overall design of my robot.

Check list to build such a robot:

A chassis preferably like this : You should be able to easily drill holes in the chassis to adjust the motors and the wheels. The chassis should have enough space to keep an arduino board along with the receiver circuit and connections to the motor for the wheels.

Simple DC Motors . These motors are again easily available in hardware stores. Also their data sheets are easily available on the Internet. To interface these kind of motors to an Arduino Duemilanove, we use a current driver circuit, namely using L293D IC. The pin numbers 4,5,6,7 are connected to the Arduino board which gives digital outputs to this circuit. The data sheet of the L293D, current driver circuit can be found here.

The rf transmitters as shown above work on 433 Hz. The RF transmitters and receivers can be used with Arduino board using the library “VirtualWire.h”. The library has a ready-made template for sender and receiver. The template can then be modified and used so! The Arduino board can be ordered from different portals, and it costs a bit. But the board is very user-friendly and is open source. It has a great and an active discussion forum and community!

Apart from these basic electronics, some electronics like resistors, leds, wires , wire stripper and pliers are always handy. 😀

P.S.: If you are starting to learn a new micro controller, using Arduino will be the best option! Though other micro controllers can also be used, Arduino is my personal favourite. 🙂

Advertisements

10 comments

  1. haha.. I remember this. We were supposed to do this together. But at the end, somehow I managed to piss you off.

  2. Lashantha · · Reply

    Hi…I would like to do something similar to this for my final project….What visual aid did you use with arduino board and if you could explain the program?

    1. Hey,
      Firstly sorry for the late reply. I basically used camera feed in OpenCV. I used the function CVFitEllipse to determine what kind of shape is being seen. Once the shape is detected, the information is relayed to the Receiver on top of the bot and directions are given to pursue the detected shape.

  3. Hi,
    can you more specific about the image processing with opencv? like the steps and the function you used?
    thx.

    1. Hey!

      As far as the image processing with OpenCV is concerned, firstly I did thresholding to separate different colours. Once thresholded, I applied CVFitEllipse Technique to determine different shapes.

      1. And after opencv detect the shape,, what command did you use to communicate your bot?

      2. Hey,

        Once shape was detected, its co-ordinates were found. After finding the co-ordinates, a tentative direction was found. This direction information was sent over RF to the robot’s micro-controller. The robot’s micro-controller received instructions as to how to move the motors. As far as communication is concerned, C and RF communication can be established.

  4. whats the processor size of both the bots(running linux + catching one )…please…

    1. Hey,

      I used Arduino D. boards on the bot which was chasing, while a normal laptop with 2Gb ram was used to run linux. Hope this solves your query.

  5. keyur savaliya · · Reply

    hey,
    i want to give a ht 12e and ht 12d programming by the communication purpose so i hop you all fully supported to me. . .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: