Ask Your Question

How to determine the axis of a prolonged object?

asked 2019-01-08 02:13:45 -0500

image description

The angle of the line is of primary interest. I know an algorithm for ellipse (will post it here as answer later), but would like to find out what is popular for an arbitrary shape. Fast methods are preferable for work with video input.

edit retag flag offensive close merge delete



Yes, this is classics. It is based on the method of least squares. Only I guess it will be not very fast? By the way, do you know how modern math processors work? In the past, floating point arithmetic was substantially slower than integer numbers. Now I tested and the speed is the same.

ya_ocv_user gravatar imageya_ocv_user ( 2019-01-08 04:39:08 -0500 )edit

I'm sorry... are you looking for the line and the angle, or just the angle?

sjhalayka gravatar imagesjhalayka ( 2019-01-08 10:50:52 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-01-09 11:03:56 -0500

sjhalayka gravatar image

updated 2019-01-09 17:56:01 -0500

If you have the end points of the line, then getting the angle is pretty straightforward:

#include <iostream>
#include <cmath>
using namespace std;

int main(void)
    float x0 = 0.0f;
    float y0 = 0.0f;

    float x1 = 1.0f;
    float y1 = 1.0f;

    float rise = y1 - y0;
    float run  = x1 - x0;

    float pi = 4.0f*atanf(1.0f);

    float slope = rise/run;

    float angle_radians = atanf(slope);
    float angle_degrees = angle_radians/pi*180.0f;

    cout << rise << endl;
    cout << run << endl;
    cout << angle_radians << endl;
    cout << angle_degrees << endl;

    return 0;
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-01-08 02:13:45 -0500

Seen: 57 times

Last updated: Jan 09