Copy from lk_homography.py