annotate scripts/extract-camera-parameters.py @ 1211:a095d4fbb2ea

work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 02 May 2023 07:12:26 -0400
parents cc5cb04b04b0
children
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: 895
diff changeset
1 #! /usr/bin/env python3
895
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3 import argparse
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4
1028
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 998
diff changeset
5 from trafficintelligence import storage, cvutils
895
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
6
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
7 parser = argparse.ArgumentParser(description='The program extracts the intrinsic camera from the tacal camera calibration file used by T-Analyst (http://www.tft.lth.se/en/research/video-analysis/co-operation/software/t-analyst/).')
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8 parser.add_argument('-i', dest = 'filename', help = 'filename of the camera calibration (.tacal)', required = True)
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9 parser.add_argument('-o', dest = 'outputIntrinsicFilename', help = 'filename of the intrinsic camera matrix', default = 'intrinsic-camera.txt')
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11 args = parser.parse_args()
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
12
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
13 cameraData = storage.loadPinholeCameraModel(args.filename, True)
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
14 if cameraData is not None:
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
15 from numpy import savetxt
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
16 intrinsicCameraMatrix = cvutils.getIntrinsicCameraMatrix(cameraData)
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
17 distortionCoefficients = cvutils.getDistortionCoefficients(cameraData)
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
18 savetxt(args.outputIntrinsicFilename, intrinsicCameraMatrix)
739acd338cc0 added script to extract camera info from tacal file by Lund University (T analyst)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
19 print(distortionCoefficients)