Yolo 多任务推理,摄像头+视频实时推理,实现关键点、分割、检测等模型推理部署

Yolo 多任务推理

支持检测、分类、分割、OBB旋转框检测、POSE关键点检测;支持图片、视频、摄像头实时推理

部分源码:

python 复制代码
import os
import sys
import time
from dataclasses import dataclass
from pathlib import Path
from typing import List, Optional, Tuple

import cv2
import numpy as np
import onnxruntime as ort
from PySide6.QtCore import QPoint, QTimer, Qt
from PySide6.QtGui import QImage, QPainter, QPixmap
from PySide6.QtWidgets import (
    QApplication,
    QComboBox,
    QDoubleSpinBox,
    QFileDialog,
    QFormLayout,
    QGroupBox,
    QHBoxLayout,
    QLabel,
    QLineEdit,
    QMainWindow,
    QMessageBox,
    QPushButton,
    QSpinBox,
    QVBoxLayout,
    QWidget,
)


IMAGE_EXTS = {".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff", ".webp"}
POSE_SKELETON = [
    (0, 1), (0, 2), (1, 3), (2, 4),
    (5, 6), (5, 7), (7, 9), (6, 8), (8, 10),
    (5, 11), (6, 12), (11, 12),
    (11, 13), (13, 15), (12, 14), (14, 16),
]


@dataclass
class Detection:
    cls_id: int
    conf: float
    bbox: Tuple[int, int, int, int]


@dataclass
class OBBDetection:
    cls_id: int
    conf: float
    cx: float
    cy: float
    w: float
    h: float
    angle_deg: float


class ZoomPanLabel(QLabel):
    def __init__(self, text: str = ""):
        super().__init__(text)
        self._pixmap: Optional[QPixmap] = None
        self._scale = 1.0
        self._offset = QPoint(0, 0)
        self._dragging = False
        self._last_pos = QPoint(0, 0)
        self.setAlignment(Qt.AlignCenter)
        self.setStyleSheet("background:#1e1e1e;color:#cccccc;border:1px solid #444;")

    def set_image(self, pixmap: QPixmap):
        self._pixmap = pixmap
        self._scale = 1.0
        self._offset = QPoint(0, 0)
        self.update()

    def wheelEvent(self, event):
        if self._pixmap is None:
            return
        delta = event.angleDelta().y()
        factor = 1.15 if delta > 0 else 1 / 1.15
        self._scale = float(np.clip(self._scale * factor, 0.1, 20.0))
        self.update()

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton and self._pixmap is not None:
            self._dragging = True
            self._last_pos = event.position().toPoint()
            self.setCursor(Qt.ClosedHandCursor)
        super().mousePressEvent(event)

    def mouseMoveEvent(self, event):
        if self._dragging and self._pixmap is not None:
            cur = event.position().toPoint()
            delta = cur - self._last_pos
            self._last_pos = cur
            self._offset += delta
            self.update()
        super().mouseMoveEvent(event)

    def mouseReleaseEvent(self, event):
        if event.button() == Qt.LeftButton:
            self._dragging = False
            self.setCursor(Qt.ArrowCursor)
        super().mouseReleaseEvent(event)

    def mouseDoubleClickEvent(self, event):
        self._scale = 1.0
        self._offset = QPoint(0, 0)
        self.update()
        super().mouseDoubleClickEvent(event)

    def paintEvent(self, event):
        super().paintEvent(event)
        if self._pixmap is None:
            return
        painter = QPainter(self)
        painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        sw = int(self._pixmap.width() * self._scale)
        sh = int(self._pixmap.height() * self._scale)
        scaled = self._pixmap.scaled(sw, sh, Qt.KeepAspectRatio, Qt.SmoothTransformation)
        x = (self.width() - scaled.width()) // 2 + self._offset.x()
        y = (self.height() - scaled.height()) // 2 + self._offset.y()
        painter.drawPixmap(x, y, scaled)

实现效果

检测:
分割:
分类:
关键点:
视频推理:
完整演示:

https://live.csdn.net/v/522949

相关推荐
用户8356290780514 小时前
Python 操作 PDF 附件:添加、查看与管理指南
后端·python
宇宙之一粟12 小时前
乐企版式文件生成平台
java·后端·python
学测绘的小杨1 天前
CompassFusion:一个从 GNSS 到 GNSS/INS 组合导航的独立工程包
python
zzzzzz3101 天前
当产品经理说这个很简单:我用Python自动化处理奇葩需求的实战指南
python·pycharm·产品经理
雪隐1 天前
个人电脑玩AI-06让5060 Ti给你打工——不光能画画,Qwen3-TTS还能学人说话,连我老板都信了!
人工智能·后端·python
兵慌码乱2 天前
面向桌面端的资产管理系统分层架构设计与核心模块实现
python·系统架构·sqlite·pyqt5·数据库设计·桌面应用开发·mvc架构
hboot2 天前
AI工程师第三课 - 机器学习基础
python·scikit-learn·kaggle
顾林海2 天前
Agent入门阶段-编程基础-Python:流程控制
python·agent·ai编程
呱呱复呱呱2 天前
Django CBV 源码解读:一个请求是怎么找到你的 get() 方法的
python·django
曲幽3 天前
刚部署的 LibreTranslate 频频翻车?我掏出了 20 年前的 StarDict 词典,用 FastAPI 搭了个本地词典翻译 API
python·fastapi·web·translate·goldendict·libretranslate·stardict·pystardict