@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "CoreML",
3
3
  "name": "@camera.ui/camera-ui-coreml",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "description": "camera.ui coreml plugin",
6
6
  "author": "seydx (https://github.com/seydx/camera.ui)",
7
7
  "main": "./src/main.py",
@@ -83,46 +83,47 @@ class CameraDetector:
83
83
  self.start()
84
84
 
85
85
  async def __detect(self):
86
- try:
87
- async for frame in self.camera.get_motion_frames():
88
- frame_image = await frame.to_image(
89
- {
90
- "format": {"to": "rgb"},
91
- "resize": {
92
- "width": self.object_detector.input_width,
93
- "height": self.object_detector.input_height,
94
- },
95
- }
96
- )
97
-
98
- detections: list[Detection] = []
99
-
100
- class_ids, scores, boxes = await self.object_detector.detect(frame_image["image"])
101
-
102
- for class_id, score, box in zip(class_ids, scores, boxes):
103
- x1, y1, x2, y2 = box
104
-
105
- detection: Detection = {
106
- "id": str(uuid4()),
107
- "label": cast(ObjectClass, self.object_detector.labels[class_id]),
108
- "confidence": score,
109
- "boundingBox": (float(x1), float(y1), float(x2), float(y2)),
110
- "inputWidth": self.object_detector.input_width,
111
- "inputHeight": self.object_detector.input_height,
112
- "origWidth": frame.metadata["origWidth"],
113
- "origHeight": frame.metadata["origHeight"],
114
- }
115
-
116
- detections.append(detection)
117
-
118
- await self.camera.update_state("object", {"detections": detections})
119
- except asyncio.CancelledError:
120
- pass
121
- except Exception as error:
122
- self.logger.error(self.camera.name, "Error generating motion frames", error)
123
- finally:
124
- if not self.closed:
125
- self.restart()
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)