Mercurial Hosting > traffic-intelligence
annotate scripts/rescale-homography.py @ 981:c3e690c5536e
corrected bug in display trajectories
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 27 Feb 2018 15:24:57 -0500 |
parents | 56cc8a1f7082 |
children | 933670761a57 |
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 |
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 |