Optical Flow Error

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:

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

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.