Overload resolution failed: Can’t parse ‘pt1’. Sequence item with index 0 has a wrong type

I’m trying to implement optical flow following Python OpenCV: Optical Flow with Lucas-Kanade method - GeeksforGeeks
however, running the below line generates the below error

mask = cv2.line(mask, (a, b), (c, d),color[i].tolist(), 2)

Error:
cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function ‘line’

Overload resolution failed:

  • Can’t parse ‘pt1’. Sequence item with index 0 has a wrong type
  • Can’t parse ‘pt1’. Sequence item with index 0 has a wrong type

Any suggestion how to solve it?

you should pass new.ravel().astype(int) and old.ravel().astype(int)

and make sure to use a package made from the current release of OpenCV, which is v4.7.0 right now. if you recently installed with pip install opencv-python, that is the case.

you need to understand that the Geeks-for-Geeks site contains poor quality articles. that is one of them. they never seem to have executed their code. what they present there shouldn’t have worked at all. the circle() call wants integers but it’s probably getting floats. in past versions of OpenCV, the Python bindings even complained if they were given numpy integers but that’s okay now.

OpenCV: OpenCV modules is the official documentation and it comes with tutorials.

2 Likes