Mercurial Hosting > traffic-intelligence
comparison scripts/rescale-homography.py @ 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 | |
children | 56cc8a1f7082 |
comparison
equal
deleted
inserted
replaced
412:97cb5c969ef2 | 413:8f8f4375e441 |
---|---|
1 #! /usr/bin/env python | |
2 | |
3 import sys | |
4 | |
5 import matplotlib.pyplot as plt | |
6 import numpy as np | |
7 import cv2 | |
8 | |
9 import cvutils | |
10 import utils | |
11 | |
12 if len(sys.argv) < 4: | |
13 print('Usage: {} homography_filename original_size new_size (size can be width or height)'.format(sys.argv[0])) | |
14 sys.exit() | |
15 | |
16 homography = np.loadtxt(sys.argv[1]) | |
17 | |
18 imgPoints = np.array([[10,10], | |
19 [10,20], | |
20 [20,20], | |
21 [20,10]]) | |
22 | |
23 wldPoints = cvutils.projectArray(homography, imgPoints.T).T | |
24 | |
25 newSize = float(sys.argv[3]) | |
26 originalSize = float(sys.argv[2]) | |
27 imgPoints = imgPoints*newSize/originalSize | |
28 | |
29 newHomography, mask = cv2.findHomography(imgPoints, wldPoints) | |
30 | |
31 np.savetxt(sys.argv[1]+'.new', newHomography) | |
32 |