ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Drone Line Follower

asked 2017-09-16 10:42:22 -0500

mikerosz gravatar image

updated 2017-09-16 11:10:28 -0500

jayess gravatar image

Hello everyone, I am working a project where I want to follow a straight line to clean gutters. I read up on opencv for image processing. This is my thought process:

  1. Perform Erosion/Dilation Operations on your image to get rid of extra space, if necessary.
  2. Call cv::findContours() to get a trace around the edges of the white regions in your image.
  3. Sort your found contours by pixel area to find the contour you want to follow.
  4. follow the largest pixel area. Try using the contour moments.
  5. Fit a line to the contour using cv::fitline() or your own approach.
  6. Take the angle of the line and map it to your drone controller to adjust the yaw.

Set a contour pixel mass threshold. If the contour area > threshold, move up. Look at the shape of the threshold area. If it is more like a trapezoid than a rectangle, you can adjust your roll/pitch.

My problem is how do I feed images to the drone, for the drone to detect the gutter and follow a straight line. How do I code the movements? Also what streaming service will recognize opencv. The code I have is node.js because I am not sure how to use the C++ / Python Version of OpenCV. But i want to use the c++ version because there are more capabilities.

var cv = require('C:/users/danny/codes/node_modules/opencv/lib/opencv');
// (B)lue, (G)reen, (R)ed
var lower_threshold = [220, 220, 220];
var upper_threshold = [255, 255, 255];

//var lower_threshold = [46, 57, 83];
//var upper_threshold = [80, 96, 115];

  function(err, im) {
    if (err) throw err;
    if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size');

    im.inRange(lower_threshold, upper_threshold);'C://users/danny/codes/coin_detected.jpg');
    console.log('Image saved to C://users/danny/codes/coin_detected.jpg');
edit retag flag offensive close merge delete


What operating system are you using? It looks like you're using Windows.

jayess gravatar image jayess  ( 2017-09-16 11:23:52 -0500 )edit

yes windows

mikerosz gravatar image mikerosz  ( 2017-09-19 12:06:38 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-09-16 13:11:37 -0500

jayess gravatar image

I'm going to use ardrone_autonomy as an example because I'm familiar with it. There are other options out there though.

My problem is how do I feed images to the drone, for the drone to detect the gutter and follow a straight line

Do you mean get the camera feed from the drone? To get the images from the drone you're going to need to subscribe to the topic that is carrying those images. ardrone_autonomy publishes images from the bottom camera on the ardrone/bottom/image_raw and from the front camera on the ardrone/bottom/image_raw topic.

Once you're getting your images, you can use cv_bridge to convert between ROS Image messages and OpenCV images. Then you can use OpenCV to do some image processing and figuring out the commands that you need to send to your drone.

How do I code the movements?

Well, this part is up to you. You decide how you want to control your drone (you can probably start with a simple proportional controller and go from there). Once you know what you need to tell your drone what to do, you send your commands along the cmd_vel topic.

Also what streaming service will recognize opencv?

Can you clarify?


You can mix and match languages with ROS by using different nodes. This is good news because you can learn just enough Python and/or C++ to work with OpenCV and stick to whatever language you're comfortable with (as long as it's supported).

Each node can be written in different langues via the supported client libraries. There are experimental ones (such as rosnodejs) so just make sure that you read up on the ones that you choose to use before you use them (your safe with the main client libraries though).

edit flag offensive delete link more

Question Tools



Asked: 2017-09-16 10:42:22 -0500

Seen: 1,050 times

Last updated: Sep 16 '17