I am trying to implement monocular (single camera) Visual Odometry in OpenCV Python. Wikipedia gives the commonly used steps for approach here http://en.wikipedia.org/wiki/Visual_odometry I calculated Optical Flow using Lucas Kanade tracker. The code is given here http://docs.opencv.org/trunk/doc/py_tutorials/py_video/py_lucas_kanade/py_lucas_kanade.html Step 4 on Wiki says "Check flow field vectors for potential tracking errors and remove outliers". How do I do this in OpenCV (python)? What algorithm/function should I use? And what about steps 5 and 6? I read somewhere (see third comment http://opencv-users.1802565.n2.nabble.com/optical-flow-with-kalman-filter-td6578617.html) that Kalman Filter would not give any improvement in performance if Lucas Kanade is used.
3
votes
Can you rebuild opencv?
- Martijn van Wezel
stackoverflow.com/questions/7388893/…
- Martijn van Wezel
I'm still a beginner, but I can say one say. As far as I know, removing outliers are done by RANSAC algorithm. And there's many algorithms in OpenCV that use RANSAC method, given to it as a flag. I don't actually think that you need to implement all these stuff by yourself, maybe there's a function in OpenCV for the whole algorithm .. maybe not. I'm still searching. If I reached something, I'd let you know.
- Rou
1 Answers
0
votes
As for removing vectors with errors, you should filter keypoints in accordance with status returned by calcOpticalFlowPyrLK. The following code can help you with it:
def featureTracking(image_ref, image_cur, px_ref):
kp2, st, err = cv2.calcOpticalFlowPyrLK(image_ref, image_cur, px_ref, None, **lk_params) # shape: [k,2] [k,1] [k,1]
st = st.reshape(st.shape[0])
kp1 = px_ref[st == 1]
kp2 = kp2[st == 1]
return kp1, kp2
As for steps 5 and 6, find essential matrix and estimate pose using it (openCV functions findEssentialMat and recoverPose. You can look through these examples:
And read this two posts: