annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
413
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1 #! /usr/bin/env python
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3 import sys
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5 import matplotlib.pyplot as plt
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
6 import numpy as np
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
7 import cv2
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9 import cvutils
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10 import utils
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
12 if len(sys.argv) < 4:
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
13 print('Usage: {} homography_filename original_size new_size (size can be width or height)'.format(sys.argv[0]))
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
14 sys.exit()
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
15
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
16 homography = np.loadtxt(sys.argv[1])
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
17
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
18 imgPoints = np.array([[10,10],
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
19 [10,20],
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
20 [20,20],
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
21 [20,10]])
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
22
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
23 wldPoints = cvutils.projectArray(homography, imgPoints.T).T
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
24
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
25 newSize = float(sys.argv[3])
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
26 originalSize = float(sys.argv[2])
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
27 imgPoints = imgPoints*newSize/originalSize
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
28
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
29 newHomography, mask = cv2.findHomography(imgPoints, wldPoints)
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
30
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
31 np.savetxt(sys.argv[1]+'.new', newHomography)
8f8f4375e441 forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
32