Skip to content

Potential type error when using float coordinates in visualization functions #1065

@irealmatin

Description

@irealmatin

In the Optical Flow example, the following code is used to unpack points:

for i, (new, old) in enumerate(zip(good_new, good_old)):
    a, b = new.ravel() 
    c, d = old.ravel()

This works fine for calculations. However, if good_new and good_old contain float coordinates, using a and b directly in OpenCV drawing functions (e.g., cv2.line, cv2.circle) may cause a type error, since these functions expect integer pixel coordinates.

Convert the coordinates to integers when using them for visualization:

a, b = new.ravel().astype(int)
c, d = old.ravel().astype(int)

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