robopark 2.8.19 → 2.8.21
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/vision/app_pi_clean.py +15 -2
package/package.json
CHANGED
package/vision/app_pi_clean.py
CHANGED
|
@@ -3,6 +3,7 @@ from flask_cors import CORS
|
|
|
3
3
|
import argparse
|
|
4
4
|
import cv2
|
|
5
5
|
import os
|
|
6
|
+
import sys
|
|
6
7
|
import time
|
|
7
8
|
import numpy as np
|
|
8
9
|
import threading
|
|
@@ -16,10 +17,22 @@ CORS(app)
|
|
|
16
17
|
current_camera_index = 0
|
|
17
18
|
camera = None
|
|
18
19
|
|
|
20
|
+
def _open_camera(index):
|
|
21
|
+
# On Windows, cv2.VideoCapture(index) with no explicit backend can
|
|
22
|
+
# auto-probe into an unrelated backend (e.g. Orbbec's "obsensor") that
|
|
23
|
+
# fails with "Camera index out of range" for a perfectly normal UVC
|
|
24
|
+
# webcam — isOpened() then stays False forever and callers retry in an
|
|
25
|
+
# infinite doomed loop. Force DirectShow, the backend that actually
|
|
26
|
+
# enumerates standard Windows webcams.
|
|
27
|
+
if sys.platform == 'win32':
|
|
28
|
+
return cv2.VideoCapture(index, cv2.CAP_DSHOW)
|
|
29
|
+
return cv2.VideoCapture(index)
|
|
30
|
+
|
|
31
|
+
|
|
19
32
|
def get_camera():
|
|
20
33
|
global camera, current_camera_index
|
|
21
34
|
if camera is None or not camera.isOpened():
|
|
22
|
-
camera =
|
|
35
|
+
camera = _open_camera(current_camera_index)
|
|
23
36
|
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
|
|
24
37
|
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
|
25
38
|
print(f"Camera {current_camera_index} initialized")
|
|
@@ -223,7 +236,7 @@ def caption_mode():
|
|
|
223
236
|
def list_cameras():
|
|
224
237
|
available = []
|
|
225
238
|
for i in range(4):
|
|
226
|
-
cap =
|
|
239
|
+
cap = _open_camera(i)
|
|
227
240
|
if cap.isOpened():
|
|
228
241
|
available.append({"index": i, "name": f"Camera {i}"})
|
|
229
242
|
cap.release()
|