Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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-

C++
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;

                    }

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
Posted
Updated 18-Dec-14 10:28am
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900