Opencv: Extract a double type from pixels (cols, rows, x, y)
I'm working with information given in pixels, because I'm interested in object's tracking. I created a vector which stores five positions in x-axis.
X[i] = track_window.x + track_window.width;
As a physics student, I would like to proceed an acceleration's calculus using finite difference equations with middle-point method (what I mean can be explored here or simply in the following line).
ax = (-X[0] + 16*X[1] - 30*X[2] + 16*X[3] - X[4])/(12*dt*dt);
But in OpenCV a position in pixels is given as an integer, right? This rounding is doing a huge mess as the error propagates. My last attempt was "scaling" it, saying that "int 40 pixels in image represents double 0.07 meters in the real world". I would like to know if there's a way to force the core library to give me a double value. I've already tried:
- casting:
xmin = (double) track_window.x; - using a class from Point's structure:
Point2f
Thank you in advance!
Edit:The type declaration and the code's sequence follow:
#define diameter 0.07625
//proceed object (a circle named id)'s detection
double scale = diameter/2*radius[id];
Point2f center = centers[id];
Point2f offset = Point (radius[id], radius[id]);
//Create a ROI which is constantly updated using meanshift function
Rect track_window (center - offset, center + offset);
double xmin = 0.0;
double w = 0.0;
//Physics variables
vector<float> X(4), Y(4);
TickMeter tm; //time
tm.start();
double dt = 0.0;
double ax = 0.0;
while (true)
{
xmin = (double) track_window.x;
w = (double) track_window.width;
tm.stop();
dt = tm.getTimeSec();
if (i < 4){
X[i] = xmin + w/2; //center of ROI
}
if (i>=4){
ax = (double)(-X[0] + 16*X[1] - 30*X[2] + 16*X[3] - X[4])*scale/(12*dt*dt);
}
}
Example of results:
- X[2] = 495, 512, 525, 541...
- ax = -54.2062, -542.359, 466.908, -349.999
The thing is, the data for displacement (X[3]-X[1]) and velocity (X[3]-X[1])/dt is well-behaved like the x-axis vector indicates. But acceleration seems to be fuzzy, as the data changes from negative to positive values constantly.
from Recent Questions - Stack Overflow https://ift.tt/2JKjvgw
https://ift.tt/eA8V8J
Comments
Post a Comment