windows test
This commit is contained in:
@@ -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,18 +124,15 @@ 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)
|
||||
|
||||
self.cap = create_capture(cam_index)
|
||||
|
||||
if self.cap is None:
|
||||
sys.exit(1)
|
||||
|
||||
for _ in range(10):
|
||||
self.cap.read()
|
||||
|
||||
if not self.cap.isOpened():
|
||||
if self.cap is None:
|
||||
sys.exit(1)
|
||||
|
||||
def update_frame(self):
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user