i am trying to implement an algorithm to estimate motion given two Images. I have used sift algorithm for feature detection.
sift = cv2.xfeatures2d.SIFT_create()
kp, des = sift.detectAndCompute(image_gray,None)
I also used the Brut force matcher for matching the features of the Images
bf = cv2.BFMatcher()
match = bf.knnMatch(des1,des2, k=2)
bestmatch = []
for m,n in match:
if m.distance < 0.4*n.distance:
bestmatch.append([m])
hence i tried to estimate the camera motion by solving for the rotational matrix and translational vector using findessentialmatrix
rmat = np.eye(3)
tvec = np.zeros((3, 1))
image1_points = []
image2_points = []
for ma in bestmatch:
ma=ma[0]
queryidx = mi.queryIdx
trainidx = mi.trainIdx
x1, y1 = kp1[queryidx].pt
image1_points.append([x1, y1])
x2, y2 = kp2[trainidx].pt
image2_points.append([x2, y2])
E,mask=cv2.findEssentialMat(np.array(image1_points),np.array(image2_points),dataset_handler.k,method=cv2.RANSAC, prob=0.999, threshold=0.5)
retval,R,t,mask=cv2.recoverPose(E,np.array(image1_points),np.array(image2_points),dataset_handler.k)
romat = R
transvec = t
the result was not good. Below is an example of what my result looked like as well as the translational vector and rotational Matrix.
Estimated rotation: was a 3X3 with values not upto 1 including negative values
Estimated translation: 3 x 1 vectors with values not upto one and also a negative value

