I'm running the optical flow tutorial from opencv and the direct problem is the calcOpticalFlowPyrLK produces the error (-215:Assertion failed) img.depth() == CV_8U
.
I've modified the code a little bit to read grey images directly. old_grey
and frame_grey
are shape (84,84)
of uint8 type. This modification is required due to another problem with opencv - I couldn't load a video file(isopen()
gives False) (but camera stream works). Also because what i want to do ultimately would be inputting (84,84) numpy matrix.
The odd thing is, the same two image works with gunnar farneback algorithm. (the follow up dense optical flow example in tut). But I want LK because its sparse.
environment: windows 10 in conda environment
old_frame = image.imread("grey-0.png")
old_grey = old_frame#cv2.cvtColor(np.float32(old_frame), cv2.COLOR_BGR2GRAY)
p0 = cv2.goodFeaturesToTrack(old_gray, maxCorners = 50, qualityLevel = 0.3, minDistance = 7,blockSize = 7)#**feature_params)
# Create a mask image for drawing purposes
mask = np.zeros_like(old_frame)
for i in range(1,10):
frame = image.imread("grey-"+str(i)+".png")
frame_grey = frame#cv2.cvtColor(np.float32(frame), cv2.COLOR_BGR2GRAY)
# calculate optical flow
p1, st, err = cv2.calcOpticalFlowPyrLK(old_grey, frame_grey, p0, None, **lk_params)