Image.
This commit is contained in:
parent
55977d9dc4
commit
d65ea171d8
|
@ -42,15 +42,16 @@ def probabilities():
|
||||||
logger.debug("phone_data:\n%s", json.dumps(phone_data, indent=2))
|
logger.debug("phone_data:\n%s", json.dumps(phone_data, indent=2))
|
||||||
context = Context(**phone_data["data"])
|
context = Context(**phone_data["data"])
|
||||||
|
|
||||||
logger.debug("Context: %s", context)
|
#logger.debug("Context: %s", context)
|
||||||
|
|
||||||
predictions: List[dict] = []
|
predictions: List[dict] = []
|
||||||
for name, strategy in strategies.items():
|
for name, strategy in strategies.items():
|
||||||
try:
|
try:
|
||||||
|
logger.debug("Executing %s..", name)
|
||||||
start = timeit.default_timer()
|
start = timeit.default_timer()
|
||||||
prediction = strategy(context)
|
prediction = strategy(context)
|
||||||
stop = timeit.default_timer()
|
stop = timeit.default_timer()
|
||||||
logger.debug("Execution time for %s: %ss", name, stop - start)
|
logger.debug("Execution time for %s: %ss", name, round(stop - start, 3 ))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("Strategy '%s' failed:", name)
|
logger.warning("Strategy '%s' failed:", name)
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
|
||||||
import requests
|
|
||||||
|
|
||||||
import cv2
|
import requests
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
|
|
||||||
from ..util import Context, Prediction
|
from ..util import Context, Prediction
|
||||||
|
@ -12,11 +10,10 @@ def camImgStrat(context : Context) -> Prediction:
|
||||||
"""
|
"""
|
||||||
The contents of the camera image
|
The contents of the camera image
|
||||||
"""
|
"""
|
||||||
img = cv2.imread(str(Path(__file__).parent.joinpath("night.jpg")), 0)
|
img = context.image
|
||||||
average = img.mean(axis=0).mean(axis=0)
|
average = img.mean(axis=0).mean(axis=0)
|
||||||
p = Prediction()
|
p = Prediction()
|
||||||
p.weight = 0.7
|
p.weight = 0.7
|
||||||
|
|
||||||
if average < 100:
|
if average < 100:
|
||||||
p.probability = 1.0
|
p.probability = 1.0
|
||||||
p.reasons.append('Image was dark')
|
p.reasons.append('Image was dark')
|
||||||
|
|
|
@ -1,16 +1,30 @@
|
||||||
|
import base64
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
from pathlib import Path
|
||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Context:
|
class Context:
|
||||||
battery: float = 1.0
|
battery: float = 1.0
|
||||||
position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0})
|
position: Dict[str, float] = field(default_factory=lambda: {'latitude': 53.0, 'longitude': 9.0})
|
||||||
|
image: np.ndarray = None
|
||||||
|
|
||||||
# App settings
|
# App settings
|
||||||
in_australia: bool = False
|
in_australia: bool = False
|
||||||
flat_earth: 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
|
@dataclass
|
||||||
class Prediction:
|
class Prediction:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user