@camera.ui/camera-ui-coreml 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/camera_detector.py +41 -40
package/package.json
CHANGED
package/src/camera_detector.py
CHANGED
|
@@ -83,46 +83,47 @@ class CameraDetector:
|
|
|
83
83
|
self.start()
|
|
84
84
|
|
|
85
85
|
async def __detect(self):
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
86
|
+
while not self.closed:
|
|
87
|
+
try:
|
|
88
|
+
async for frame in self.camera.get_motion_frames():
|
|
89
|
+
frame_image = await frame.to_image(
|
|
90
|
+
{
|
|
91
|
+
"format": {"to": "rgb"},
|
|
92
|
+
"resize": {
|
|
93
|
+
"width": self.object_detector.input_width,
|
|
94
|
+
"height": self.object_detector.input_height,
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
detections: list[Detection] = []
|
|
100
|
+
|
|
101
|
+
class_ids, scores, boxes = await self.object_detector.detect(frame_image["image"])
|
|
102
|
+
|
|
103
|
+
for class_id, score, box in zip(class_ids, scores, boxes):
|
|
104
|
+
x1, y1, x2, y2 = box
|
|
105
|
+
|
|
106
|
+
detection: Detection = {
|
|
107
|
+
"id": str(uuid4()),
|
|
108
|
+
"label": cast(ObjectClass, self.object_detector.labels[class_id]),
|
|
109
|
+
"confidence": score,
|
|
110
|
+
"boundingBox": (float(x1), float(y1), float(x2), float(y2)),
|
|
111
|
+
"inputWidth": self.object_detector.input_width,
|
|
112
|
+
"inputHeight": self.object_detector.input_height,
|
|
113
|
+
"origWidth": frame.metadata["origWidth"],
|
|
114
|
+
"origHeight": frame.metadata["origHeight"],
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
detections.append(detection)
|
|
118
|
+
|
|
119
|
+
await self.camera.update_state("object", {"detections": detections})
|
|
120
|
+
except asyncio.CancelledError:
|
|
121
|
+
pass
|
|
122
|
+
except Exception as error:
|
|
123
|
+
self.logger.error(self.camera.name, "Error generating motion frames", error)
|
|
124
|
+
self.logger.log(self.camera.name, "Restarting object detection in 5 seconds...")
|
|
125
|
+
await asyncio.sleep(5)
|
|
126
|
+
continue
|
|
126
127
|
|
|
127
128
|
def __on_motion_detected(self, state: MotionState) -> None:
|
|
128
129
|
motion_detected = bool(state.get("state", False) or len(state["detections"]) > 0)
|