@camera.ui/camera-ui-coreml 0.0.7 → 0.0.9

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.9",
5
5
  "description": "camera.ui coreml plugin",
6
6
  "author": "seydx (https://github.com/seydx/camera.ui)",
7
7
  "main": "./src/main.py",
@@ -21,7 +21,7 @@
21
21
  "url": "https://github.com/seydx/camera.ui/issues"
22
22
  },
23
23
  "engines": {
24
- "camera.ui": ">=0.0.1",
24
+ "camera.ui": ">=0.0.17",
25
25
  "node": ">=18.12.0"
26
26
  },
27
27
  "homepage": "https://github.com/seydx/camera.ui#readme",
package/requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
1
  coremltools==7.2
2
- camera-ui-python-types==0.1.81
2
+ camera-ui-python-types==0.1.82
3
3
  requests==2.32.3
4
4
  Pillow==10.4.0
@@ -83,46 +83,50 @@ 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
+ if self.closed:
90
+ break
91
+
92
+ frame_image = await frame.to_image(
93
+ {
94
+ "format": {"to": "rgb"},
95
+ "resize": {
96
+ "width": self.object_detector.input_width,
97
+ "height": self.object_detector.input_height,
98
+ },
99
+ }
100
+ )
101
+
102
+ detections: list[Detection] = []
103
+
104
+ class_ids, scores, boxes = await self.object_detector.detect(frame_image["image"])
105
+
106
+ for class_id, score, box in zip(class_ids, scores, boxes):
107
+ x1, y1, x2, y2 = box
108
+
109
+ detection: Detection = {
110
+ "id": str(uuid4()),
111
+ "label": cast(ObjectClass, self.object_detector.labels[class_id]),
112
+ "confidence": score,
113
+ "boundingBox": (float(x1), float(y1), float(x2), float(y2)),
114
+ "inputWidth": self.object_detector.input_width,
115
+ "inputHeight": self.object_detector.input_height,
116
+ "origWidth": frame.metadata["origWidth"],
117
+ "origHeight": frame.metadata["origHeight"],
118
+ }
119
+
120
+ detections.append(detection)
121
+
122
+ await self.camera.update_state("object", {"detections": detections})
123
+ except asyncio.CancelledError:
124
+ break
125
+ except Exception as error:
126
+ self.logger.error(self.camera.name, "Error generating motion frames", error)
127
+ self.logger.log(self.camera.name, "Restarting object detection in 5 seconds...")
128
+ await asyncio.sleep(5)
129
+ continue
126
130
 
127
131
  def __on_motion_detected(self, state: MotionState) -> None:
128
132
  motion_detected = bool(state.get("state", False) or len(state["detections"]) > 0)