with a glass of water
This commit is contained in:
1 parent
a220035126
commit
31b9e85912
6 files changed
+115
-9
No files matched your search
@@ -1,14 +1,27 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
|
||||
class KnownImagePoint(BaseModel):
|
||||
height: float
|
||||
width: float
|
||||
height: float
|
||||
|
||||
@classmethod
|
||||
def from_vec(cls, vec: tuple[float, float]) -> 'KnownImagePoint':
|
||||
return cls(width=vec[0], height=vec[1])
|
||||
|
||||
|
||||
class BirdViewPoint(BaseModel):
|
||||
x: float
|
||||
y: float
|
||||
|
||||
@classmethod
|
||||
def from_vec(cls, vec: tuple[float, float]) -> 'BirdViewPoint':
|
||||
return cls(x=vec[0], y=vec[1])
|
||||
|
||||
|
||||
class KnownPoint(BaseModel):
|
||||
image: KnownImagePoint
|
||||
@@ -18,3 +31,14 @@ class KnownPoint(BaseModel):
|
||||
class VideoMetadata(BaseModel):
|
||||
knownPoints: list[KnownPoint]
|
||||
|
||||
def get_view_perspective_matrix(self) -> Optional[np.array]:
|
||||
if len(self.knownPoints) < 4:
|
||||
return None
|
||||
|
||||
empirical_source = np.float32(
|
||||
[[k.image.width, k.image.height] for k in self.knownPoints])
|
||||
empirical_target = np.float32(
|
||||
[[k.bird_view.x, k.bird_view.y] for k in self.knownPoints])
|
||||
pixel_per_meter = 100
|
||||
return cv2.getPerspectiveTransform(empirical_source,
|
||||
empirical_target * pixel_per_meter)
|
||||
Reference in new issue
Block a user