led location car

Another project using opencv, which proves again its effectiveness.

The idea is from the conversation with Associate Professor Shang, who wants to find a method to acquire location for robots in indoor environment. 

A most direct method is to place some colorful lights on the ceiling. The camera equipped on the robot takes picture upward, when it knows at least two colors and positions of lights, then it can calculate where it is using mathematical methods.

The solution in brief is:

(1) design location of colorful led lights on the ceiling

This part is a liitle challenging. We should find a way which both use least lights and provide best support for robot.

Mathmatically, two lights in a view are enough, but we consider the situation when one of light is unable to determine its color caused by environmental difference, so we decide to use three for safety.

We tried several models and finally use the hexagonal frame, which ignore led captured outside hexagonal area. Such frame can capture three leds at more than  95% situation when robot rotates view or moves to anywhere. Other frames are unstable under different view.


(2) decide the color of lights

For the color is unstable when taking pictures in different environment, HSV space are used to enhance its stability.

Seperating H channel into several parts, each parts are quite different with each other.

Maps of led lights are like 


In the first period of project, we use a car instead of robot, use color paper instead of led lights.

(3) car

Applied on raspberry, which I have played for years, the control part is not a difficult thing for me. Raspberry is an excellent device which combines the benefits of a computer and a single-chip board. Using its I/O pins, it can easily control the movement of motors. 

But the I/O current is not enough for four motors of the wheels, I add H-bridges to increase currency and it can also reverse the direction of the motor.

(4) image processing

Camera takes pictures repeatedly, transforming to HSV space and use Canny to find contours of each color spot. Examine each color of spot, search in location map, and calcaulat the position and retation of the car, saving the output to the server root.

imgHSV.jpg Result.jpg

image trandformed to HSV                                           Finding location and color correctly

(5) server

set a server on raspberry, and write monitor page, which translates the position data into car picture on the map. Add control button on the page, when clicked button, control signal id posted to server by ajax. Another program constantly waiting control signal, when it receives signal, control the motor to move accordingly.

Main codes are available on github:


By Chen Li, Wang Dongyi


Last Article Next article

Comment 评论

Share 分享

New Users 最新加入

  • hokurikustr

  • refrain

New comments 最新评论

test123: aasdas Details Apr 13 16:39
admin: Thanks! Details Apr 09 11:46
admin: Google map api Details Apr 09 11:46
lqj12: cooooooooool Details Apr 08 21:34
Yunhan Huang: 这个功能是如何实现的? Details Apr 08 13:23