Change to CAP_DSHOW for VideoCapture
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import cv2, numpy as np
|
||||
import os
|
||||
|
||||
|
||||
from Tbd.helper import CameraObject
|
||||
from Tbd.helper import CameraObject, DShowMJPGCapture
|
||||
from UI.UILogger import UILogger
|
||||
|
||||
from PySide6.QtCore import Qt, QTimer
|
||||
@@ -98,31 +97,24 @@ class SetupPage(QWidget):
|
||||
# index=None
|
||||
#)
|
||||
for index in indexToAdd:
|
||||
capture = cv2.VideoCapture(index, cv2.CAP_MSMF)
|
||||
#capture = cv2.VideoCapture(index, cv2.CAP_DSHOW)
|
||||
try:
|
||||
capture = DShowMJPGCapture(index, 2592, 1944, fourcc_substr="MJPG")
|
||||
except RuntimeError as e:
|
||||
self.logger.log(str(e))
|
||||
print(str(e))
|
||||
continue
|
||||
|
||||
capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
|
||||
capture.set(cv2.CAP_PROP_FPS, 30)
|
||||
capture.set(cv2.CAP_PROP_FRAME_WIDTH, 2592)
|
||||
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 1944)
|
||||
self.logger.log(f"Selected format: {capture.selected_format}")
|
||||
print(f"Selected format: {capture.selected_format}")
|
||||
|
||||
#capture.set(cv2.CAP_PROP_FRAME_WIDTH, 2048.0)
|
||||
#capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 1536.0)
|
||||
width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
|
||||
height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
||||
fps = capture.get(cv2.CAP_PROP_FPS)
|
||||
ret, frame = capture.read()
|
||||
if ret:
|
||||
self.logger.log(f"Actual frame shape: {frame.shape}")
|
||||
print(f"Actual frame shape: {frame.shape}")
|
||||
else:
|
||||
self.logger.log("Failed to read a frame after configuring camera")
|
||||
print("Failed to read a frame after configuring camera")
|
||||
|
||||
fourcc = int(capture.get(cv2.CAP_PROP_FOURCC))
|
||||
fourcc_str = "".join([chr((fourcc >> 8*i) & 0xFF) for i in range(4)])
|
||||
|
||||
print(f"Resolution: {width}x{height}")
|
||||
print(f"FPS: {fps}")
|
||||
print(f"Format (FOURCC): {fourcc_str}")
|
||||
self.logger.log(f"Resolution: {width}x{height}")
|
||||
self.logger.log(f"FPS: {fps}")
|
||||
self.logger.log(f"Format (FOURCC): {fourcc_str}")
|
||||
#currentcapture = cv2.VideoCapture(index, cv2.CAP_MSMF)
|
||||
|
||||
#self.logger.log("Initial frame:", w, "x", h)
|
||||
self.cameraList.append(CameraObject(
|
||||
capture=capture,
|
||||
@@ -185,7 +177,7 @@ class SetupPage(QWidget):
|
||||
index = int(self.cameraIndex.text())
|
||||
|
||||
self.release_camera()
|
||||
self.cameraObject.capture = cv2.VideoCapture(index)
|
||||
self.cameraObject.capture = cv2.VideoCapture(index, cv2.CAP_DSHOW)
|
||||
self.cameraObject.index = index
|
||||
|
||||
if not self.cameraObject.capture.isOpened():
|
||||
|
||||
Reference in New Issue
Block a user