sim vision

This commit is contained in:
matteo porta 2022-07-18 16:07:10 +02:00
parent a8e025f7a8
commit b4fe7c7279
2 changed files with 13 additions and 9 deletions

View File

@ -23,6 +23,7 @@ python -B -u "./src/main.py" \
--sim-modbus \
--sim-os-label-printer \
--sim-serial \
--sim-vision \
--style windows \
$* 2> >(sed $'s/.*/\e[31m&\e[m/' >&2) # &
# --about \

View File

@ -282,6 +282,9 @@ class Vision(Component):
tf_mode = None
# reset tflite variables
interpreter = None
if self.simulate:
tf_mode = "simulation"
interpreter = None
if tf_mode is None and "edgetpu" in self.allowed_modes:
try:
# create tflite edgetpu interpreter
@ -323,14 +326,6 @@ class Vision(Component):
self.loading_model_signal.emit({"status": "done"})
def check_features(self, frame, lock=True):
# test_box = [i * s for i, s in zip([0.2, 0.2, 0.8, 0.8], frame.shape[:2] * 2)]
# return [{
# "class": self.category_index[1],
# "score": 1.0,
# "box": test_box, # rescale detection to frame size,
# "center": self.get_center(test_box),
# "size": self.get_size(test_box),
# }]
if self.interpreter is not None and frame.shape != self.interpreter.get_input_details()[0]["shape"][1:3]:
tensor = np.expand_dims(cv2.resize(frame, self.interpreter.get_input_details()[0]["shape"][1:3], interpolation=cv2.INTER_LINEAR), axis=0)
else:
@ -338,7 +333,15 @@ class Vision(Component):
# Run inference
if lock:
self.lock.lock()
if self.tf_mode in {"edgetpu", "tflite"}:
if self.simulate or tf_mode == "simulation":
detections = {
"detection_scores": [[1.0]],
"detection_boxes": [[[0.2, 0.2, 0.8, 0.8]]],
"detection_classes": [[1]],
}
if lock:
self.lock.unlock()
elif self.tf_mode in {"edgetpu", "tflite"}:
i_d = self.interpreter.get_input_details()
# print(i_d)
o_d = self.interpreter.get_output_details()