What is Point2f and Point3f?
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.
See the corresponding documentation here. It is just a class made to store Point semantic object, that is an object that holds
x
andy
coordinates in float forPoint2f
andx
,y
andz
forPoint3f
.@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?
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++.