Providing points to VPI's PyrLK optical flow algorithm

I am trying to run VPI’s PyrLK optical flow algorithm for tracking specific points. i managed to do it in python by setting up a numpy array and then using vpi.asarray on it, but i can’t seem to be able to access the algorithm parameter struct. regardless i would prefer running it on cpp, but i don’t know how. i’ve managed to insert points into the feature array but they are all lost in 1 iteration.
my code snippet for python :

custom_points = np.array([[200,100],],dtype=np.float32)
curFeatures = vpi.asarray(custom_points)
with backend:
    optflow = vpi.OpticalFlowPyrLK(frame,curFeatures,pyramid_levels)

this works great with the rest of the code example in the library, but i can’t access the pyrLK params.

in c++ i have managed to insert points into curFeatures like this:

vpiArrayLockData(curFeatrues,VPI_LOCK_READ,VPI_ARRAY_BUFFER_HOST_AOS,&array_data);
std::vector<VPIKeypointF32> points = {{200,100}};
array_data.buffer.aos.data = points.data();
*array_data.buffer.aos.sizePointer = 1;
vpiArrayUnlock(curFeatures);

it recognizes that it tracks 1 point but it losses it after 1 iteration.
i would really appreciate any help with manually inserting points into the c++ code, if you want i can upload the entire code. thank you

Hi,

Yes, please update the complete source so we can check it further.

A common cause is that you will need to call VPI synchronize before copying the buffer to the CPU (vpiArrayLockData).

Thanks.

I have actually managed to solve this issue.
when i was removing the harris section of the provided sample code, i removed the function that turns the temp frame into gray scale because i thought its connected to harris, while in reality it was necessary for the first optical flow calculation so i always lost the points I inputted.
So the c++ sample code I have provided is enough to set points you want to track instead of relying on harris corner detector , just need to pay attention what lines of code you remove.
thank you regardless.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.