Ask Your Question
0

What is Point2f and Point3f?

asked 2018-07-27 02:49:16 -0600

masterenol gravatar image

updated 2018-09-29 19:40:55 -0600

I'm seeing these 'Point2f' and 'Point3f' keywords in the OpenCV C++ docs, but my C++ books do not cover what this 'Point2f' is and I am having a difficult time on Google on my search for an explanation. Can someone please tell where or how I can get an understanding these 'Point2f' and 'Point3f' concepts?

'Point2f' is first seen in the OpenCV Docs in "Mat - The Basic Image Container", but there is no explanation on the purpose or significance of this 'Point2f' type.

edit retag flag offensive close merge delete

Comments

1

See the corresponding documentation here. It is just a class made to store Point semantic object, that is an object that holds x and y coordinates in float for Point2f and x, y and z for Point3f.

Eduardo gravatar imageEduardo ( 2018-07-27 04:17:31 -0600 )edit

@Eduardo Thank you for this info, but I'm still very confused. What advantage does storing X and Y coordinates in this Point class have over using a normal array to store the coordinates? Why use floats when the coordinates in a matrix are integers?

masterenol gravatar imagemasterenol ( 2018-07-27 19:44:59 -0600 )edit
1

That is an object-oriented way of defining structs in C++. Using an array is slightly more cumbersome, because, in C++, you must either embed a fixed sized array into a struct or a union, or to allocate an array dynamically via malloc. The first one is efficient (and in fact, not different from OpenCV's way of defining these classes), the second one is inefficient (much slower, more complicated code, and increased danger of memory leak and corruption and crashes due to dangling invalidated pointers). OpenCV's definition doesn't use a union because it wanted the code to "look clean", to stay away from C programming style. However, newer C++ language specifications have clarified the semantic and compiler behavior issues surrounding union, therefore it should be okay to use union in C++.

rwong gravatar imagerwong ( 2018-07-28 23:07:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2018-07-28 19:37:59 -0600

rwong gravatar image

In OpenCV, coordinates can be 2-dimensional, 3-dimensional, or 4-dimensional.

The number "2", "3", and "4" refers to the number of elements (components) in the coordinate vector.

The value for each element can be stored as:

  • signed 32-bit integer, denoted with letter "i",
  • 32-bit floating point (single precision), denoted with letter "f", and
  • 64-bit floating point (double precision), denoted with letter "d".

Therefore, a 2D vector of integer values is named Point2i. Likewise, a 3D vector of 32-bit single-precision floating point values is named Point3f.

OpenCV defines a C++ type alias, named Point, is a shorthand for Point2i. This is merely for convenience and for reduce code clutter.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-07-27 02:49:16 -0600

Seen: 16,499 times

Last updated: Jul 28 '18