彩色滤光片技术OpenCV [英] Color Filter Technique OpenCV

查看:70
本文介绍了彩色滤光片技术OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读取图片并滤除颜色,这是我在以下图片中得到的结果.该代码来自opencv模块中的示例文件夹.

I am reading a picture and filtering out the colors and this is the result I get in the following images. The code is from the example folder in the opencv module.

我正在尝试将图片反馈回A.R Drone 2.0,并使无人机遵循白色.我该怎么做第二部分?

I am trying to feed the picture back to an A.R Drone 2.0 and have the drone follow the color white. How would I do the second part?

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');
  });

推荐答案

由于您的无人机可以在3D空间中移动,因此我建议在2D领域中使用一些伪代码步骤,以使您从简单的行跟随器入手.然后,您可以外推到3D并添加更多自由度以满足您的需求.

Since your drone can move in 3D-space, I will suggest some pseudo-code steps in the 2D realm to get you started with a simple line follower. Then you can extrapolate to 3D and add more degrees of freedom to meet your needs.

  1. 对图像执行侵蚀/膨胀操作以消除图像如有必要,保留额外的空间.
  2. 致电 cv :: findContours()以获得图像中白色区域边缘的痕迹.
  3. 按像素区域对找到的轮廓进行排序,以找到要遵循的轮廓.我猜想您最想跟随最大的像素区域.尝试使用等高弯矩.
  4. 使用 cv将轮廓线设置为轮廓: :fitline()或您自己的方法.
  5. 获取直线的角度并将其映射到您的无人机控制器以调整偏航.
  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. I'd guess that you'd most often want to follow the largest pixel area. Try using the contour moments.
  4. Fit a line to the contour using cv::fitline() or your own approach.
  5. Take the angle of the line and map it to your drone controller to adjust the yaw.

在这里,您可以执行其他几项基本操作来控制无人机的运动:

From here, you can do several other basic things to control the motion of your drone:

  • 设置轮廓像素质量阈值.如果轮廓区域>阈值,则向上移动.
  • 查看阈值区域的形状.如果它更像是梯形而不是矩形,则可以调整滚动/倾斜.

这篇关于彩色滤光片技术OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆