Mercurial Hosting > traffic-intelligence
annotate scripts/rescale-homography.py @ 478:d337bffd7283
Display of points in compute homography and step option to replay videos
A bug seems to remain with respect to trajectory bounds, to check
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 27 Mar 2014 11:40:28 -0400 |
parents | 8f8f4375e441 |
children | 56cc8a1f7082 |
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 |