Mercurial Hosting > traffic-intelligence
changeset 413:8f8f4375e441
forgot to add homography rescaling script
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 02 Sep 2013 23:46:31 -0400 |
parents | 97cb5c969ef2 |
children | 040e71067ff4 |
files | scripts/rescale-homography.py |
diffstat | 1 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/rescale-homography.py Mon Sep 02 23:46:31 2013 -0400 @@ -0,0 +1,32 @@ +#! /usr/bin/env python + +import sys + +import matplotlib.pyplot as plt +import numpy as np +import cv2 + +import cvutils +import utils + +if len(sys.argv) < 4: + print('Usage: {} homography_filename original_size new_size (size can be width or height)'.format(sys.argv[0])) + sys.exit() + +homography = np.loadtxt(sys.argv[1]) + +imgPoints = np.array([[10,10], + [10,20], + [20,20], + [20,10]]) + +wldPoints = cvutils.projectArray(homography, imgPoints.T).T + +newSize = float(sys.argv[3]) +originalSize = float(sys.argv[2]) +imgPoints = imgPoints*newSize/originalSize + +newHomography, mask = cv2.findHomography(imgPoints, wldPoints) + +np.savetxt(sys.argv[1]+'.new', newHomography) +