annotate scripts/rescale-homography.py @ 998:933670761a57

updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 27 May 2018 23:22:48 -0400
parents 56cc8a1f7082
children cc5cb04b04b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
998
933670761a57 updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 936
diff changeset
1 #! /usr/bin/env python3
413
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
936
56cc8a1f7082 removed all old versions of projection methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 413
diff changeset
23 wldPoints = cvutils.homographyProject(imgPoints.T, homography).T
413
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