Version 2.4.1 is advertised to allow you to pass pyramids into calcOpticalFlowPyrLK. However, this doesn't work for me in Python:
>>> import cv2
>>> cv2.__version__
'2.4.1'
>>> prev_features = np.array((10, 10))
>>> im = np.zeros((100, 100), dtype = np.uint8)
>>> im2 = im.copy()
>>> pyr2 = cv2.buildOpticalFlowPyramid(im2, (8, 8), 3)
>>> pyr1 = cv2.buildOpticalFlowPyramid(im, (8, 8), 3)
>>> pyr2 = pyr2[1]
>>> pyr1 = pyr1[1]
>>> prev_features = np.array((10, 10), dtype = np.int32)
>>> res = cv2.calcOpticalFlowPyrLK(pyr1, pyr2, prev_features)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: <unknown> is not a numpy array
Whereas using simple images passes that check:
>>> res = cv2.calcOpticalFlowPyrLK(im, im2, prev_features)
OpenCV Error: Assertion failed ((npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0) in calcOpticalFlowPyrLK, file /home/anatoliy/Downloads/OpenCV-2.4.1/modules/video/src/lkpyramid.cpp, line 593
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cv2.error: /home/anatoliy/Downloads/OpenCV-2.4.1/modules/video/src/lkpyramid.cpp:593: error: (-215) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function calcOpticalFlowPyrLK
Thanks!