python - Cannot figure out what input to use to get cv2.calcOpticalFlowPyrLK method to work -


i trying make program in python opencv user can define points on video , optical flow track it.

i tried create own coordinates in form of numpy array , tried pass calcopticalflowpyrlk method in opencv, error instead:

traceback (most recent call last):     p1, st, err = cv2.calcopticalflowpyrlk(old_gray, frame_gray, d, none, **lk_params) error: /build/buildd/opencv-2.4.8+dfsg1/modules/video/src/lkpyramid.cpp:593: error: (-215) (npoints = prevptsmat.checkvector(2, cv_32f, true)) >= 0 in function calcopticalflowpyrlk 

my code:

# params shitomasi corner detection feature_params = dict( maxcorners = 1,                        qualitylevel = 0.01,                        mindistance = 10,                        blocksize = 7 )   p0 = np.array([[[348.0, 251.0]]]) # calculate optical flow p1, st, err = cv2.calcopticalflowpyrlk(old_gray, frame_gray, p0, none, **lk_params) 

i know caused p0 variable because if make p0 this:

p0 = cv2.goodfeaturestotrack(old_gray, mask = mask_use, **feature_params) 

and pass calcopticalflowpyrlk parameter, works. trying make program in user defines points, if create own coordinates , pass p0 calcopticalflowpyrlk parameter this:

d = np.array([[[348.0, 251.0]]]) p1, st, err = cv2.calcopticalflowpyrlk(old_gray, frame_gray, d, none, **lk_params) 

then end getting error.

what numpy array have create calcopticalflowpyrlk method accept?

from docs:

prevpts – vector of 2d points flow needs found; point coordinates must single-precision floating-point numbers

so p0 must vector of 2d points:

p0 = [[x0, y0], [x1, y1], [x2, y2]] 

so 1 point, expect work:

p0 = [[348.0, 251.0]] 

i think you've used many brackets , few.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -