去除FFMPEG后端

This commit is contained in:
2025-12-19 08:56:58 +08:00
parent c51757f66b
commit 8c0727990e
22 changed files with 163 additions and 33 deletions

View File

@@ -1,9 +1,7 @@
import cv2
from PyQt5.QtCore import qDebug
from .base_thread import BaseThread
from .structures import ImageFrame
from .utils import gstreamer_pipeline
@@ -11,11 +9,10 @@ class CaptureThread(BaseThread):
def __init__(self,
device_id,
# flip_method=2,
flip_method=0,
drop_if_full=True,
api_preference=cv2.CAP_ANY,
resolution=None,
# use_gst=None,
parent=None):
"""
device_id: device number of the camera.
@@ -27,8 +24,7 @@ class CaptureThread(BaseThread):
"""
super(CaptureThread, self).__init__(parent)
self.device_id = device_id
# self.flip_method = flip_method
# self.use_gst = None
self.flip_method = flip_method
self.drop_if_full = drop_if_full
self.api_preference = api_preference
self.resolution = resolution
@@ -61,15 +57,25 @@ class CaptureThread(BaseThread):
continue
# retrieve frame and add it to buffer
_, frame = self.cap.retrieve()
_, frame = self.cap.read()
# Skip empty frames (e.g., when camera capture times out)
if frame is None or frame.size == 0:
continue
# Apply image flip if needed
if self.flip_method == 2:
frame = cv2.rotate(frame, cv2.ROTATE_180)
# frame = cv2.resize(frame, (960, 640))
img_frame = ImageFrame(self.clock.msecsSinceStartOfDay(), frame)
self.buffer_manager.get_device(self.device_id).add(img_frame, self.drop_if_full)
# update statistics
self.update_fps(self.processing_time)
self.stat_data.frames_processed_count += 1
# inform GUI of updated statistics
self.update_statistics_gui.emit(self.stat_data)
# self.update_fps(self.processing_time)
# self.stat_data.frames_processed_count += 1
# # inform GUI of updated statistics
# self.update_statistics_gui.emit(self.stat_data)
qDebug("Stopping capture thread...")
@@ -83,7 +89,6 @@ class CaptureThread(BaseThread):
# try to set camera resolution
if self.resolution is not None:
width, height = self.resolution
self.cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"YUYV"))
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)