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

相关推荐
circuitsosk19 分钟前
平台整体能力与功能特性设计:分群、联运、ABTest与运营位系统
python·机器学习·搜索引擎·ab测试·vllm·rag检索
Livia要学习25 分钟前
Python三种常见高阶函数--map、filter、sorted
开发语言·python
冷咖啡离 我的笨笨39 分钟前
用最简单的例子,从最简单的设计开始,重构着讲解设计原则与模式——从DIP中“倒置”的含义说接口的正确使用
python·重构·依赖倒置原则
PC2005-cloud1 小时前
FinalShell 自定义背景图片教程
ide·python·pycharm
傻啦嘿哟10 小时前
某短视频平台视频爬虫实战:抓取推荐流视频信息,绕过反爬的3种技巧
开发语言·爬虫·python
迷迭香yy10 小时前
集合竞价数据挖掘实战:用Python构建开盘信号识别系统
人工智能·python·数据挖掘
李昊哲小课13 小时前
fastapi sse websocket 奶茶店实时订单看板
人工智能·python·websocket·网络协议·fastapi·sse
2401_8445829515 小时前
工具包:软件架构设计的实用技巧与经验分享
python
RFID固定资产管理系统15 小时前
适配媒体行业的固定资产管理软件有哪些功能与核心优势
大数据·人工智能·python·媒体
SunnyDays101115 小时前
Python 为 PowerPoint 添加动画:进入、退出、动作路径与文本动画(详解)
python·powerpoint·动画·动画效果·文本动画