# Optical Flow Error

**URL:** <https://forum.opencv.org/t/optical-flow-error/3414>\
**Category:** Python\
**Created:** [May 19, 2021, 11:37am UTC](https://forum.opencv.org/t/optical-flow-error/3414 "2021-05-19T11:37:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_h](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/chris_h/32/2143_2.png) [@Chris\_h](https://forum.opencv.org/u/Chris_h)\
**Post date:** [May 19, 2021, 11:37am UTC](https://forum.opencv.org/t/optical-flow-error/3414/1 "2021-05-19T11:37:26Z")

</div>

Hello guys,

currently trying to create a code which in will be using for surface tension measurements and I have a problem with the tracking part. Does someone have an idea?

```
Traceback (most recent call last):
  File "/Users/chris/PycharmProjects/surfacetension/main.py", line 62, in <module>
    cv2.circle(frame, (x, y), 5, (0, 255, 0), -1)
cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'circle'
> Overload resolution failed:
> - Can't parse 'center'. Sequence item with index 0 has a wrong type
> - Can't parse 'center'. Sequence item with index 0 has a wrong type

```

This is the code, I am using right now:

```python
import numpy as np
import cv2

# %% Working
# creating the old frame and video input
cap = cv2.VideoCapture(1)
ret, frame = cap.read()
old_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# video information
frame_width = int(cap.get(3))
frame_length = int(cap.get(4))

# video recording - not working yet, missing the right video format for OSX
'''
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('test.avi', fourcc, 23.0, (frame_width, frame_length))
'''

# Lucas kanade params
lk_params = dict(winSize=(15, 15),
                 maxLevel=4,
                 criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03))

# Mouse integration
def select_point(event, x, y, flags, params):
    global point, point_selected, old_points
    if event == cv2.EVENT_LBUTTONDOWN:
        point = (x, y)
        point_selected = True
        old_points = np.array([[x, y]], dtype=np.float32)

cv2.namedWindow("Frame")
cv2.setMouseCallback("Frame", select_point)

point_selected = False
point = ()
old_points = np.array([[]])

while True:
    ret, frame = cap.read()
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    if point_selected is True:
        cv2.circle(frame, point, 6, (0, 0, 255), 2,)

        new_points, status, error = cv2.calcOpticalFlowPyrLK(old_gray, gray_frame, old_points, None, **lk_params)
        old_gray = gray_frame.copy()
        print(new_points)
        new_points = old_points

        x, y = new_points.ravel()
        cv2.circle(frame, (x, y), 5, (0, 255, 0), -1)

    # video output
    cv2.imshow("Frame", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# %%
cap.release()
# out.release()
cv2.destroyAllWindows()

```

My second question would be, if any of you has a working video recording method for the current version of OS X.

Thanks a lot for your help!

Best wishes,  
Chris

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [May 19, 2021, 3:48pm UTC](https://forum.opencv.org/t/optical-flow-error/3414/3 "2021-05-19T15:48:34Z")

</div>

the type of `x` and `y` must be integer. if it’s a float, this error will happen.

feel free to file a bug report (or find an existing bug report) and ask for error messages that are better than that.

> <https://github.com/opencv/opencv/blob/68d15fc62edad980f1ffa15ee478438335f39cc3/modules/python/src2/cv2.cpp#L490>
