Mercurial Hosting > traffic-intelligence
annotate scripts/rescale-homography.py @ 1242:4cd8ace3552f
major update for classification, allowing the use of neural network classification
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 07 Feb 2024 11:43:03 -0500 |
parents | cc5cb04b04b0 |
children |
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 |
1028
cc5cb04b04b0
major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
998
diff
changeset
|
9 from trafficintelligence import cvutils, utils |
413
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
10 |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
11 if len(sys.argv) < 4: |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 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
|
13 sys.exit() |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
14 |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
15 homography = np.loadtxt(sys.argv[1]) |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
16 |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
17 imgPoints = np.array([[10,10], |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
18 [10,20], |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
19 [20,20], |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
20 [20,10]]) |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
21 |
936
56cc8a1f7082
removed all old versions of projection methods
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
413
diff
changeset
|
22 wldPoints = cvutils.homographyProject(imgPoints.T, homography).T |
413
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
23 |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
24 newSize = float(sys.argv[3]) |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
25 originalSize = float(sys.argv[2]) |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
26 imgPoints = imgPoints*newSize/originalSize |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
27 |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
28 newHomography, mask = cv2.findHomography(imgPoints, wldPoints) |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
29 |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
30 np.savetxt(sys.argv[1]+'.new', newHomography) |
8f8f4375e441
forgot to add homography rescaling script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
31 |