I have two images which are registered with AKAZE/ORB algorithm. Post to this registration, I need to further refine the registration using optical flow methods. I have used the below code to do the same.
def warp_flow(img1, img2):
img1_gray = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
img2_gray = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
flow = cv2.calcOpticalFlowFarneback(img1_gray, img2_gray, None, 0.1, 3, 15, 3, 5, 1.2, 0)
h, w = flow.shape[:2]
flow = -flow
flow[:,:,0] += np.arange(w)
flow[:,:,1] += np.arange(h)[:,np.newaxis]
res = cv2.remap(img2, flow, None, cv2.INTER_NEAREST)
return res
But the result is very poor. This is the first input to optical flow, This is the second input to optical flow and This image is the output from optical flow. This clearly shows there is smearing happening when using optical flow. Please help me to figure out how to correct this and get a correct warping using optical flow.