0

Rosanswers logo

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];

cv.readImage('C:/users/danny/codes/node_modules/opencv/examples/files/gutter.jpg', 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);
im.save('C://users/danny/codes/coin_detected.jpg');
console.log('Image saved to C://users/danny/codes/coin_detected.jpg');

});


Originally posted by mikerosz on ROS Answers with karma: 21 on 2017-09-16

Post score: 0


Original comments

Comment by jayess on 2017-09-16:
What operating system are you using? It looks like you're using Windows.

Comment by mikerosz on 2017-09-19:
yes windows

1 Answers1

0

Rosanswers logo

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?

Note:

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).


Originally posted by jayess with karma: 6155 on 2017-09-16

This answer was ACCEPTED on the original site

Post score: 0