This repository has been archived by the owner on Dec 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
camera.py
36 lines (32 loc) · 1.39 KB
/
camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Pedestrian Tracking
2018
POVa - Computer Vision
FIT - Faculty of Information Technology
BUT - Brno University of Technology
"""
from typing import Tuple
import numpy as np
class Camera:
def __init__(self, name: str, focal_length: float, position: Tuple[int, int, int],
orientation: Tuple[int, int, int]):
"""
:param name: camera name used in user interface
:param focal_length: focal length of camera, see `Camera.calibrate_focal_length`
:param position: 3D coordinates of the camera position
:param orientation: 3D vector of the camera's view orientation
"""
self.name = name
self.focal_length = focal_length
self.position = position
self.orientation = orientation / np.linalg.norm(orientation) # convert to unit vector
@staticmethod
def calibrate_focal_length(real_distance: int, real_size: int, pixel_size: int) -> float:
"""
Calibrate focal length of the camera based on measurement of known object and its image representation.
:param real_distance: real distance of known object from camera in millimeters
:param real_size: real size size of known object in millimeters,
:param pixel_size: size of known object measured in pixels in image obtained from the camera
:return: focal length
"""
return (pixel_size * real_distance) / real_size