windows test

This commit is contained in:
Thies Mueller
2026-04-23 18:53:32 +02:00
parent 75537258a7
commit 07ecb4ffb1
+22 -35
View File
@@ -23,47 +23,35 @@ def save_config(cfg):
CONFIG = load_config()
def create_capture(index):
backends = []
if sys.platform == "darwin":
backends = [
cv2.CAP_AVFOUNDATION,
cv2.CAP_ANY
]
elif os.name == "nt":
backends = [
cv2.CAP_DSHOW,
cv2.CAP_MSMF,
cv2.CAP_ANY
]
if os.name == "nt":
cap = cv2.VideoCapture(index, cv2.CAP_DSHOW)
else:
backends = [
cv2.CAP_V4L2,
cv2.CAP_ANY
]
cap = cv2.VideoCapture(index)
for backend in backends:
cap = cv2.VideoCapture(index, backend)
if not cap.isOpened():
return None
if not cap.isOpened():
continue
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
for _ in range(10):
ret, frame = cap.read()
if ret and frame is not None:
return cap
cap.release()
for _ in range(20):
ret, frame = cap.read()
if ret and frame is not None:
return cap
cap.release()
return None
def find_cameras():
working = []
for i in range(2):
for i in range(10):
cap = create_capture(i)
if cap is not None:
working.append(i)
cap.release()
@@ -123,6 +111,8 @@ class PhotoApp(QWidget):
def init_camera(self):
cams = find_cameras()
if not cams:
sys.exit(1)
last = CONFIG.get("camera", {}).get("last_used")
if last in cams:
@@ -134,6 +124,9 @@ class PhotoApp(QWidget):
QApplication.processEvents()
cam_index = selector.selected
if cam_index is None:
sys.exit(1)
CONFIG["camera"]["last_used"] = cam_index
save_config(CONFIG)
@@ -142,12 +135,6 @@ class PhotoApp(QWidget):
if self.cap is None:
sys.exit(1)
for _ in range(10):
self.cap.read()
if not self.cap.isOpened():
sys.exit(1)
def update_frame(self):
if not self.cap:
return
@@ -175,7 +162,7 @@ class PhotoApp(QWidget):
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
h, w, ch = rgb.shape
img = QImage(rgb.data, w, h, ch * w, QImage.Format.Format_RGB888)
img = QImage(rgb.data, w, h, ch * w, QImage.Format.Format_RGB888).copy()
pix = QPixmap.fromImage(img)
painter = QPainter(pix)