Skip to content

bug report: histogram generation #2

@Tigerwander

Description

@Tigerwander

during computing histogram, distance and angle between each two contour points.
the code for angle computing is as follows:
`
double angle(Point& p1, Point& p2)
{
int ydif = p2.y - p1.y;
int xdif = p2.x - p1.x;

 if (xdif == 0)
 {
     if (ydif < 0) return (-1.0 * M_PI/2.0);
     else return (M_PI / 2.0);
 }

 float slope = ydif / xdif;
 double theta = atan(slope);

 if (theta > 0 && xdif > 0) theta = theta;
 if (theta > 0 && xdif < 0) theta = theta + M_PI;
 else if (theta < 0 && xdif > 0) theta = theta + M_PI * 3.0 / 4.0;
 else theta = theta + M_PI / 2.0;
 cout << p1 << ", " << p2 << endl;

 return theta;

}
while when using angle to fill angleBins, as follows
double ang = angle(p1, p2);
int angleBin = (int) floor(ang / angleSize);
if angle generation, when two points has same x axes, for example (169, 56) and (169, 27), and the second y is smaller than first y, then the 4th line code will take on
if (ydif < 0) return (-1.0 * M_PI/2.0);
which, will get a negative angle, make the angleBin as negative, two, but, angleBin ranges [0, 12] So, I think it's a bug. Yes, this bug happens to me. It can be modified as
if (ydif < 0) return (M_PI + M_PI/2.0);
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions