1 | initial version |
Hello,
This is a very late answer to your problem, you probably solved it yourself already. I thought it might be of help for others (like me) who are struggling with this method in OpenCV.
It seems to me that you do NOT need to use the function cv2.buildOpticalFlowPyramid() AT ALL to work with pyramids. The parameter maxLevel in cv2.OpticalFlowPyrLK() is used to determine the maximum level of the pyramid intrinsically built by the function.
This is quite confusing in the documentation of OpenCV, I hope they will change it soon. Took me way too long to figure this out:
`
lk_params = dict(winSize=(21, 21),
maxLevel=3, # number oflayers of your pyramid
criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 30, 0.01))
def KLT_featureTracking(image_ref, image_cur, px_ref):
kp2, st, err = cv2.calcOpticalFlowPyrLK(image_ref, image_cur, px_ref, None, **lk_params)
kp1, st, err = cv2.calcOpticalFlowPyrLK(image_cur, image_ref, kp2, None, **lk_params)
` This should work. For older versions of OpenCV: cv2.buildOpticalFlowPyramid() returns two values, number of layers and pyramid itself. This was probably the problem of @jads_96
Best wishes!