tinesight 0.0.6.dev1__tar.gz → 0.0.10.dev1__tar.gz
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.
- {tinesight-0.0.6.dev1 → tinesight-0.0.10.dev1}/PKG-INFO +1 -1
- {tinesight-0.0.6.dev1 → tinesight-0.0.10.dev1}/pyproject.toml +3 -1
- {tinesight-0.0.6.dev1 → tinesight-0.0.10.dev1}/src/tinesight/client.py +61 -10
- {tinesight-0.0.6.dev1 → tinesight-0.0.10.dev1}/README.md +0 -0
- {tinesight-0.0.6.dev1 → tinesight-0.0.10.dev1}/src/tinesight/__init__.py +0 -0
- {tinesight-0.0.6.dev1 → tinesight-0.0.10.dev1}/src/tinesight/_api.py +0 -0
- {tinesight-0.0.6.dev1 → tinesight-0.0.10.dev1}/src/tinesight/registrar.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "tinesight"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.10.dev1"
|
|
4
4
|
description = "Tinesight SDK"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -12,6 +12,8 @@ dependencies = [
|
|
|
12
12
|
[project.optional-dependencies]
|
|
13
13
|
video = [
|
|
14
14
|
"opencv-python>=4.13.0.90",
|
|
15
|
+
# "python-prctl; sys_platform == 'linux'",
|
|
16
|
+
# "picamera2; sys_platform== 'linux'",
|
|
15
17
|
]
|
|
16
18
|
|
|
17
19
|
[build-system]
|
|
@@ -27,6 +27,15 @@ class TinesightClient(TinesightApiMixin):
|
|
|
27
27
|
"""Private wrapper for making invoking requests with a certa"""
|
|
28
28
|
return partial(requests.post, cert=(self.cert_path, self.key_path))
|
|
29
29
|
|
|
30
|
+
def _is_raspberry_pi(self) -> bool:
|
|
31
|
+
"""Check if running on a Raspberry Pi"""
|
|
32
|
+
try:
|
|
33
|
+
with open("/proc/device-tree/model", "r") as f:
|
|
34
|
+
model = f.read()
|
|
35
|
+
return "Raspberry Pi" in model
|
|
36
|
+
except FileNotFoundError:
|
|
37
|
+
return False
|
|
38
|
+
|
|
30
39
|
def __init__(self, x509_key_path: Path | str, x509_cert_path: Path | str):
|
|
31
40
|
self.key_path: str = str(x509_key_path)
|
|
32
41
|
self.cert_path: str = str(x509_cert_path)
|
|
@@ -92,12 +101,34 @@ class TinesightClient(TinesightApiMixin):
|
|
|
92
101
|
"OpenCV is required for video streaming. Install with: pip install opencv-python"
|
|
93
102
|
)
|
|
94
103
|
|
|
95
|
-
#
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
# Check if we should use picamera2 (Raspberry Pi with CSI camera)
|
|
105
|
+
use_picamera2 = False
|
|
106
|
+
picam2 = None
|
|
107
|
+
|
|
108
|
+
if isinstance(video_source, int) and self._is_raspberry_pi():
|
|
109
|
+
try:
|
|
110
|
+
from picamera2 import Picamera2
|
|
111
|
+
|
|
112
|
+
use_picamera2 = True
|
|
113
|
+
print("Detected Raspberry Pi - using picamera2 for CSI camera")
|
|
114
|
+
except ImportError:
|
|
115
|
+
print("picamera2 not available, falling back to OpenCV")
|
|
116
|
+
|
|
117
|
+
# Initialize camera
|
|
118
|
+
if use_picamera2:
|
|
119
|
+
picam2 = Picamera2()
|
|
120
|
+
config = picam2.create_preview_configuration(
|
|
121
|
+
main={"size": (640, 480), "format": "RGB888"}
|
|
122
|
+
)
|
|
123
|
+
picam2.configure(config)
|
|
124
|
+
picam2.start()
|
|
125
|
+
print("Starting picamera2 stream")
|
|
126
|
+
else:
|
|
127
|
+
cap = cv2.VideoCapture(video_source)
|
|
128
|
+
if not cap.isOpened():
|
|
129
|
+
raise RuntimeError(f"Could not open video source: {video_source}")
|
|
130
|
+
print(f"Starting video stream from: {video_source}")
|
|
99
131
|
|
|
100
|
-
print(f"Starting video stream from: {video_source}")
|
|
101
132
|
print(f"Classifying every {frame_skip} frames")
|
|
102
133
|
print("Press Ctrl+C to stop")
|
|
103
134
|
|
|
@@ -111,12 +142,29 @@ class TinesightClient(TinesightApiMixin):
|
|
|
111
142
|
|
|
112
143
|
try:
|
|
113
144
|
while True:
|
|
114
|
-
|
|
145
|
+
# Capture frame based on camera type
|
|
146
|
+
if use_picamera2:
|
|
147
|
+
try:
|
|
148
|
+
frame = picam2.capture_array()
|
|
149
|
+
# picamera2 returns RGB, convert to BGR for OpenCV
|
|
150
|
+
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
|
|
151
|
+
ret = True
|
|
152
|
+
except Exception as e:
|
|
153
|
+
print(f"Failed to capture frame from picamera2: {e}")
|
|
154
|
+
ret = False
|
|
155
|
+
else:
|
|
156
|
+
ret, frame = cap.read()
|
|
157
|
+
|
|
115
158
|
if not ret:
|
|
116
159
|
print("Failed to read frame, attempting to reconnect...")
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
160
|
+
if use_picamera2:
|
|
161
|
+
picam2.stop()
|
|
162
|
+
time.sleep(1)
|
|
163
|
+
picam2.start()
|
|
164
|
+
else:
|
|
165
|
+
cap.release()
|
|
166
|
+
time.sleep(1)
|
|
167
|
+
cap = cv2.VideoCapture(video_source)
|
|
120
168
|
continue
|
|
121
169
|
|
|
122
170
|
# Calculate FPS
|
|
@@ -221,5 +269,8 @@ class TinesightClient(TinesightApiMixin):
|
|
|
221
269
|
except KeyboardInterrupt:
|
|
222
270
|
print("\nStopping video stream...")
|
|
223
271
|
finally:
|
|
224
|
-
|
|
272
|
+
if use_picamera2 and picam2:
|
|
273
|
+
picam2.stop()
|
|
274
|
+
elif not use_picamera2:
|
|
275
|
+
cap.release()
|
|
225
276
|
cv2.destroyAllWindows()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|