35 lines
984 B
Python
35 lines
984 B
Python
import base64
|
|
import random
|
|
from dataclasses import dataclass, field
|
|
from pathlib import Path
|
|
from typing import List, Dict
|
|
|
|
import cv2
|
|
import numpy as np
|
|
|
|
|
|
@dataclass
|
|
class Context:
|
|
battery: int = field(default_factory=lambda: random.randint(0, 100))
|
|
position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0}) # Denmark somewhere
|
|
image: np.ndarray = None
|
|
|
|
# App settings
|
|
in_australia: bool = False
|
|
flat_earth: bool = False
|
|
|
|
def __post_init__(self):
|
|
if self.image is None: # no image given
|
|
self.image = cv2.imread(str(Path(__file__).parent.joinpath("gray.png")))
|
|
else:
|
|
img_original = base64.b64decode(self.image)
|
|
img_as_np = np.frombuffer(img_original, dtype=np.uint8)
|
|
self.image = cv2.imdecode(img_as_np, flags=1)
|
|
|
|
|
|
@dataclass
|
|
class Prediction:
|
|
probability: float = 0.5
|
|
weight: float = 1.0
|
|
reasons: List[str] = field(default_factory=list)
|