cv2.VideoCapture 跳帧取图

该博客围绕 cv2.VideoCapture 进行跳帧取图操作,虽未给出具体内容,但推测是关于利用此工具实现视频跳帧获取图像的信息技术相关内容。
def run(self): try: if isinstance(self.source, int) or isinstance(self.source, str) or self.source.endswith(('.mp4', '.avi', '.mov')): # 视频或摄像头 cap = cv2.VideoCapture(self.source) while self.running and cap.isOpened(): ret, frame = cap.read() if not ret: break # 保存原始帧 original_frame = frame.copy() # 检测 results = self.model(frame, conf=self.conf, iou=self.iou) annotated_frame = results[0].plot() # 提检测结果 detections = [] for result in results: for box in result.boxes: class_id = int(box.cls) class_name = self.model.names[class_id] confidence = float(box.conf) x, y, w, h = box.xywh[0].tolist() detections.append((class_name, confidence, x, y)) # 发送信号 self.frame_received.emit( cv2.cvtColor(original_frame, cv2.COLOR_BGR2RGB), cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB), detections ) # 控制帧率 #time.sleep(0.03) # 约30fps time.sleep(0.01) # 约30fps cap.release() else: # 片 frame = cv2.imread(self.source) if frame is not None: original_frame = frame.copy() results = self.model(frame, conf=self.conf, iou=self.iou) annotated_frame = results[0].plot() # 提检测结果 detections = [] for result in results: for box in result.boxes: class_id = int(box.cls) class_name = self.model.names[class_id] confidence = float(box.conf) x, y, w, h = box.xywh[0].tolist() detections.append((class_name, confidence, x, y)) self.frame_received.emit( cv2.cvtColor(original_frame, cv2.COLOR_BGR2RGB), cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB), detections ) except Exception as e: print(f"Detection error: {e}") finally: self.finished_signal.emit() 网络摄像头检测,存在严重的视频流延迟问题,如何处理该问题
最新发布
08-27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值