跟踪摄像机中的物体; PID控制;鹦鹉AR无人机2 [英] Tracking objects from camera; PID controlling; Parrot AR Drone 2

查看:109
本文介绍了跟踪摄像机中的物体; PID控制;鹦鹉AR无人机2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我应该使用Parrot AR Drone 2.0的摄像头实现对象跟踪技术.因此,主要思想是,无人机应该能够识别指定的颜色,然后通过保持一定距离来跟随它.

I am working on a project where I should implement object tracking technique using the camera of Parrot AR Drone 2.0. So the main idea is, a drone should be able to identify a specified colour and then follow it by keeping some distance.

我正在使用 opencv API与无人机建立通信.该API提供功能:

I am using the opencv API to establish communication with the drone. This API provides function:

ARDrone::move3D(double vx, double vy, double vz, double vr)

它将AR.Drone在3D空间中移动到

which moves the AR.Drone in 3D space and where

  • vx:X速度[m/s]
  • vy:Y速度[m/s]
  • vz:Z速度[m/s]
  • vr:转速[rad/s]

我编写了一个应用程序,该应用程序使用OpenCV对从无人机的摄像头获得的图像进行简单的图像处理,并找到需要跟踪的对象的轮廓.请参见下面的示例:

I have written an application which does simple image processing on the images obtained from the camera of the drone using OpenCV and finds needed contours of the object to be tracked. See the example below:

现在 我正在努力的部分 正在寻找一种技术,通过该技术我应该找到 速度 发送到 move3D 函数.我已经读到,进行控制的常见方法是使用 PID 进行控制.但是,我已经阅读了有关此内容,但无法了解它与该问题的关系.

Now the part I am struggling is finding the technique using which I should find the velocities to be sent to the move3D function. I have read that common way of doing controlling is by using PID controlling. However, I have read about that and could not get how it could be related to this problem.

总而言之,我的问题是如何将机器人移向其相机中检测到的物体?如何从相机中找到某些物体的坐标?

To summarise, my question is how to move a robot towards an object detected in its camera? How to find coordinates of certain objects from the camera?

推荐答案


因此,我刚刚意识到您使用的是无人机,而坐标系WRT则无人机可能x向前进入图像,y向图像左侧(图像列),z垂直向上(图像行).我的答案的坐标是WRT,摄像机x =列,y =行,z =深度(图像)当您阅读我的轮廓时,请牢记.而且我写的都是伪代码,没有很多修改就不会运行


So, I just realized you are using a drone and your cordinate system WRT the drone is likely x forward into image, y left of image (image columns), z up vertically(image rows). My answer has coordinates WRT the camera x = columns, y = rows, z = depth (into image) Keep that n mind when you read my outline. Also everything I wrote is psuedo-code, it won't run without many modifications

原始帖子:
PID控制器是比例积分微分控制器.它会根据您的特定错误来决定要执行的操作.

Original Post:
A PID controller is a Proportional–integral–derivative controller. It decides an action sequenced based on the your specific error.

对于您的问题,让我们假设最佳跟踪意味着矩形位于图像的中心,并且占据约30%的像素空间.这意味着您必须移动相机/机器人,直到满足这些条件.我们将这些目标参数称为

For your problem lets assume the optimal tracking means the rectangle is in the center of the image, and it takes up ~30% of the pixel space. This means that you move your camera/bot until these conditions are met. We will call these goal parameters

x_ideal = image_width / 2
y_ideal = image_height / 2
area_ideal = image_width * image_height * 0.3

现在可以说您的边界框具有4个参数

Now lets say your bounding box is characterized by 4 parameters

(x_bounding, y_bounding, width_bounding_box, height_bounding_box)

您的错误可能是由于以下原因造成的:

Your error would be something along the lines of:

x_err = x_bounding - x_ideal;
y_err = y_bounding - y_ideal;
z_err = area_ideal - (width_bounding_box * height_bounding_box)

注意,我已将z距离(深度)与对象的大小绑定在一起.这假定被跟踪的对象是刚性的,并且不会更改大小.尺寸上的任何变化都是由于物体与相机的距离(较大的边框表示物体靠近,而较小的边界框则表示物体较远).这只是一个估计,但是如果没有相机或物体本身的任何参数,我们只能做出这些一般性声明.

Notice I have tied the z distance (depth) to the size of the object. This assumes that the object being tracked is rigid and doesn't change size. Any change in size is due to the objects distance to the camera (a bigger bounding box means object is close, a small one means object is far). This is a bit of an estimation, but without having any parameters on the camera or the object itself we can only make these general statements.

在创建控制序列时,我们需要牢记符号,这就是为什么在进行减法时顺序很重要的原因.让我们从逻辑上考虑一下. x_err确定边界框与所需位置的水平距离.在我们的例子中,这应该是肯定的,这意味着漫游器应该向左移动,从而使对象向图像中心靠拢.盒子太小,意味着物体太远了,等等.

We need to keep the sign in mind when creating our control sequences, this is why the order matters when doing subtraction. Lets think about this logically. x_err determines how far off the bounding box is horizontally from the desired position. In our case this should be positive, meaning the bot should move to the left so the object moves closer to the center of the image. The box is too small, meaning the object is too far away, etc.

z_err< 0:表示漫游器距离太近,需要降低速度,应降低Vz
z_err = 0:保持速度命令不变,不改变
z_err> 0:我们需要接近,Vz应该增加

z_err < 0 : means bot is too close and needs to slow down, Vz should be reduced
z_err = 0 : keep the speed command the same, no change
z_err > 0 : we need to get closer, Vz should increase

x_err< 0:表示机器人在右边,需要向左转(x减小),应减小Vx
x_err = 0:保持X的速度相同,而对Vx保持不变
x_err> 0:表示机器人在左侧,需要向右转(x增大),Vx应该增大

x_err < 0 : means bot is to the right and needs to turn left(decreasing x), Vx should be reduced
x_err = 0 : keep the speed in X the same, no change to Vx
x_err > 0 : means bot is to the left and needs to turn right(increasing x), Vx should be increased

我们可以对每个y轴执行相同的操作.现在,我们使用此错误为机器人创建命令序列.

We can do the same for each y axis. Now we use this error to create a command sequence for the bot.

听起来很像PID控制器.观察状态,找出错误,创建控制序列以减少错误,然后一遍又一遍地重复该过程.在您的情况下,速度将是算法输出的动作.实际上,您将有3个PID在运行

That description sounds a lot like a PID controller. Observe a state, figure out an error, create a control sequence to reduce the error, then repeat the process over and over. In your case the velocity would be the actions output by your algorithm. You will essentially have 3 PIDs running

  1. X的PID
  2. Y的PID
  3. Z的PID
  1. PID for X
  2. PID for Y
  3. PID for Z

因为它们本质上是正交的,所以我们可以说每个系统都是独立的(理想情况下是独立的),在x方向上移动不会影响Y方向.这个示例也完全忽略了方位信息(Vr),但这只是一个思想练习,而不是一个完整的解决方案

Because these are orthogonal by nature, we can say each system is independent (and ideally it is), moving in the x direction shouldn't affect the Y direction. This example also completely ignores the bearing information (Vr), but it's meant to be a thought exercise, not a complete solution

校正的确切速度由您的PID系数确定,这会使事情变得有些棘手. 此处是易于阅读的(几乎没有数学的)概述或PID控制.您将需要通过一些实验来使用系统(也就是调整"您的参数).由于相机不是一个完整的3D传感器,这变得更加困难,因此我们无法从环境中提取真实的测量结果.在不了解有关您的传感器/环境的更多信息的情况下,很难将~30 pixels的错误转换为m/s,但是我希望这可以使您对如何进行操作有一个大致的了解

The exact velocity of the corrections is determined by your PID coefficients and this is where things get a little tricky. Here is a easy to read (almost no math) overview or PID control. You will have to play with your system (aka "Tune" your parameters) through a bit of experimentation. This is made even more difficult because the camera is not a full 3d sensor, so we can't extract true measurements from the environment. It hard to convert an error of ~30 pixels into m/s without knowing more information about your sensor/environment, But I hope this gave you a general idea of how to proceed

这篇关于跟踪摄像机中的物体; PID控制;鹦鹉AR无人机2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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