在opencv和c ++中查找对象的不同位置之间的距离 [英] Finding distance between different positions of an object in opencv and c++

查看:90
本文介绍了在opencv和c ++中查找对象的不同位置之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序来检测特定对象的颜色并在网络摄像头框架中跟踪它。我的目标是我想找到物体从新点到前一点的距离。这是我的代码,我将在代码后解释问题 -



I have written a program to detect a particular object by its color and track it in the webcam frame. My goal is that i want to find the distance of the object from the new point to the previous point. This is my code and i will explain the problem after the code-

x = moment.m10/area;
                  y = moment.m01/area;
                  Point a;
                  a = Point(x,y);
                                    vector<Point> cont(0);
                  cont.push_back(a);
                    for(int i= 0; i < (cont.size()-1); i++)
                  {
                    p = pow((cont.at(i).x - cont.at(i+1).x),2);
                    q = pow((cont.at(i).y - cont.at(i+1).y),2);
                    r = sqrt(p+q);
                    cout<<r<<endl;

                    }



现在,如果我在网络摄像头框架中有多个对象,我只能得到距离它给了我object1和object2之间的距离是否正确。但我想要的是使用相同的逻辑计算单个物体从当前位置到新位置的距离。



请任何人帮助我。我真的很困惑,因为我不知道我做错了什么。谢谢


Now, i only get the distance if i have more than one object in the webcam frame and it gives me the distance between object1 and object2 correctly. But what i want is to calculate the distance of a single object from the current position to the new position using the same logic.

Please can anyone help me out. I am really confused as i have no clue where i am doing wrong. Thanks

推荐答案

您必须创建所有对象的快照(对象列表),其位置为您的开始时间。在结束时你会制作另一个快照。并且你可以计算。



使用面向对象的设计是显而易见的。为对象提供一个ID(唯一标识符),以便在不同的快照中找到它们。
you must make a "snapshot" (object list) of all objects with its position to your start time. And at the endtime you make another "snapshot". And than you can calc.

The use of an object oriented design is obvious. Give the objects an ID (unique identifier) to find them in different snapshots.


这篇关于在opencv和c ++中查找对象的不同位置之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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