# Image registration using optical flow

**URL:** <https://forum.opencv.org/t/image-registration-using-optical-flow/757>\
**Category:** Python\
**Created:** [January 9, 2021, 7:24pm UTC](https://forum.opencv.org/t/image-registration-using-optical-flow/757 "2021-01-09T19:24:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajsal\_shereef](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ajsal_shereef/32/489_2.png) [@ajsal\_shereef](https://forum.opencv.org/u/ajsal_shereef)\
**Post date:** [January 9, 2021, 7:24pm UTC](https://forum.opencv.org/t/image-registration-using-optical-flow/757/1 "2021-01-09T19:24:36Z")

</div>

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](https://i.stack.imgur.com/11XGJ.jpg), [This is the second input to optical flow](https://i.stack.imgur.com/SxjcX.jpg) and [This image is the output from optical flow](https://i.stack.imgur.com/id41U.png). 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.
