opencvcomputer-visionfeature-extraction

Why is opencv feature points not an integer?


I am a little confused why the coordinate of the feature points is a float instead of an integer. Since all the pixel is integers, wouldn't it be weird to have a float feature points?

Thank you!

For example:

< cv2.KeyPoint >
special variables
function variables
angle: 313.130859375
class_id: -1
octave: 2
pt:
(516.9600219726562, 123.84000396728516)
response: 0.0013209185563027859
size: 44.6400032043457

Solution

  • I see where the confusion can be generated. You are correct: for humans, pixels are defined by integers - you either have a pixel or have none; there is no intermediate. However, if you think about it, computers are not constrained to thinking about coordinates as integers; they have no awareness of pixels when they perform operations. To them, points can be set in a world of almost infinite precision with floating-point coordinates. It is only when computers render their calculations that they have to round them up or down to fit the limitations of our screens (i.e., fit them into pixels). Using floating points as coordinate values allows computers to increase their accuracy in a wide range of tasks, ranging from performing large operations (i.e., image transformation, scaling, rotation...) to normalising coordinates (a very common task performed by OpenCV). Having said this, I have to admit that storing coordinates as floating points uses more computing power than their integer counterpart.

    You may want to take a look at OpenCV's documentation on points or at this answered question on the same topic. Conversely, you may want to take a look at an article that defends the superiority of integer coordinates over floating point coordinates. Overall, the choice of storing coordinates as floating points or integers largely depends on the task you aim to perform, and the accuracy versus efficiency balance you want to establish. In the case of OpenCV (at the time of writing this answer), they have appraised the floating-point approach as a more sensible one. Hope this helps! And may the code be with you...