Ask Your Question
0

Float or int accuracy for displaying line.

asked 2013-04-24 06:23:42 -0500

steve55 gravatar image

Hi

From the example of RotateRect in the documentation the vertices are stored in an array of Point2f which contains floating point values, the line function then draws with these values.

Mat image(200, 200, CV_8UC3, Scalar(0));
RotatedRect rRect = RotatedRect(Point2f(100,100), Size2f(100,50), 30);

Point2f vertices[4];
rRect.points(vertices);
for (int i = 0; i < 4; i++)
   line(image, vertices[i], vertices[(i+1)%4], Scalar(0,255,0));

Rect brect = rRect.boundingRect();
rectangle(image, brect, Scalar(255,0,0));

imshow("rectangles", image);
waitKey(0);

My question is why is the array created using Point2f? wouldn't it be better to use Point2i? as pixel coordinates cannot be faction numbers anyway.

Also would there be a performance penalty in using floating point instead of int?

Thanks

Steve

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-04-24 07:03:40 -0500

zerog80 gravatar image

updated 2013-04-24 07:04:46 -0500

It is created as Point2f because even if you start from Point2i, a rotation can produce floating-point coordinates and rounding them to integers can lead to accuracy loss. Given all the optimization involved in OpenCV at compile time, I don't think using floating point instead of integers can be a performance issue, since both are typedef of the same Point_ class as explained here.

At most, you can be afraid of memory occupation if integers are 16 bits and floating point are 32 bits.

edit flag offensive delete link more

Comments

1

Thanks for the answer, that makes sense to me. so i guess the accuracy can only be maintained in the float array, and once the array is plotted in pixels on the screen there may be slight error in the pixels due to rounding. This doesn't seem like a problem as the calculations will be done from the array, not the plotted pixels. Thanks again for your help.

steve55 gravatar imagesteve55 ( 2013-04-24 08:45:29 -0500 )edit

You're welcome :)

zerog80 gravatar imagezerog80 ( 2013-04-24 09:14:46 -0500 )edit

Question Tools

Stats

Asked: 2013-04-24 06:23:42 -0500

Seen: 899 times

Last updated: Apr 24 '13