I'm trying to use cv2.optflow.calcOpticalFlowSparseRLOF() to tracker the sparse point in frame series. But in the experiment, I found that if I just input one point to cv2.optflow.calcOpticalFlowSparseRLOF(), it can work well. However, if I input more than one points to the function, it can't calc the optflow and return same numbers of the input points. And the same input can work well in cv2.calcOpticalFlowPyrLK().
I have checked the type and the dimension of the input points numpy array, it is same to the result of cv2.goodFeaturesToTrack().
I don't kown what happend, thanks for the help!
```.py
from cv2 import cv2
import numpy as np
import glob
img_path = '../20200622/L'
images = glob.glob(img_path+'/*.'+'png')
images.sort()
feature_params = dict(maxCorners=100,
qualityLevel=0.3,
minDistance=7)
p0 = cv2.goodFeaturesToTrack(cv2.cvtColor(cv2.imread(images[0]), cv2.COLOR_BGR2GRAY), mask=None, **feature_params)
pts0 = np.array([[1092,534],[920,404]]).reshape(-1,1,2)
pts1 = np.zeros(np.shape(pts0))
pts0 = np.float32(pts0)
pts1 = np.float32(pts1)
for i in range(1,len(images)):
print('loop: {}'.format(i))
pimg = cv2.imread(images[i-1])
nimg = cv2.imread(images[i])
pimg_g = pimg
nimg_g = nimg
pts1, status, err = cv2.optflow.calcOpticalFlowSparseRLOF(pimg_g, nimg_g, pts0, pts1)
# lk_params = dict( winSize = (15, 15),
# maxLevel = 2,
# criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03))
# pts1, status, err = cv2.calcOpticalFlowPyrLK(pimg_g, nimg_g, pts0, None) #, **lk_params)
pts0 = pts1
```
Please try to capture input of failed case and provide minimal complete reproducer (including input images in lossless .png format - see imwrite())
I have checked the type and the dimension of the input points numpy array
Consider adding dump from cv.utils.dumpInputArray(value).
Unfortunatly I can somehow recreate this.
System information (version)
Detailed description
When tracking feature points with cv.optflow.calcOpticalFlowSparseRLOF() there is some undefined behaviour. This is is somewhat mysterious, but here's the deal:
import numpy as np
import cv2 as cv
pimg = cv.imread('/usr/share/opencv4/samples/data/basketball1.png', None)
nimg = cv.imread('/usr/share/opencv4/samples/data/basketball2.png', None)
p0 = np.array([[129, 122],[130, 111], [100, 100]], dtype=np.float32)
p1, st, err = cv.optflow.calcOpticalFlowSparseRLOF(pimg, nimg, p0, None)
# print(p1)
p1, st, err = cv.optflow.calcOpticalFlowSparseRLOF(pimg, nimg, p0, None)
print(p1)
Images are from the opencv-samples, the basketball1.png and basketball2.png.
print(p1) in between the calls, I get undefined points.[[0. 0.]] as output.I have no idea why the call has to be twice and, even more mysterious to me, how the print-statement can somehow change the results. :thinking:
Most helpful comment
Unfortunatly I can somehow recreate this.
System information (version)
Detailed description
When tracking feature points with cv.optflow.calcOpticalFlowSparseRLOF() there is some undefined behaviour. This is is somewhat mysterious, but here's the deal:
Images are from the opencv-samples, the basketball1.png and basketball2.png.
print(p1)in between the calls, I get undefined points.[[0. 0.]]as output.I have no idea why the call has to be twice and, even more mysterious to me, how the print-statement can somehow change the results. :thinking: