Yolo 多任务推理,摄像头+视频实时推理,实现关键点、分割、检测等模型推理部署
Yolo 多任务推理
支持检测、分类、分割、OBB旋转框检测、POSE关键点检测;支持图片、视频、摄像头实时推理
部分源码:
importosimportsysimporttimefromdataclassesimportdataclassfrompathlibimportPathfromtypingimportList,Optional,Tupleimportcv2importnumpyasnpimportonnxruntimeasortfromPySide6.QtCoreimportQPoint,QTimer,QtfromPySide6.QtGuiimportQImage,QPainter,QPixmapfromPySide6.QtWidgetsimport(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),]@dataclassclassDetection:cls_id:intconf:floatbbox:Tuple[int,int,int,int]@dataclassclassOBBDetection:cls_id:intconf:floatcx:floatcy:floatw:floath:floatangle_deg:floatclassZoomPanLabel(QLabel):def__init__(self,text:str=""):super().__init__(text)self._pixmap:Optional[QPixmap]=Noneself._scale=1.0self._offset=QPoint(0,0)self._dragging=Falseself._last_pos=QPoint(0,0)self.setAlignment(Qt.AlignCenter)self.setStyleSheet("background:#1e1e1e;color:#cccccc;border:1px solid #444;")defset_image(self,pixmap:QPixmap):self._pixmap=pixmap self._scale=1.0self._offset=QPoint(0,0)self.update()defwheelEvent(self,event):ifself._pixmapisNone:returndelta=event.angleDelta().y()factor=1.15ifdelta>0else1/1.15self._scale=float(np.clip(self._scale*factor,0.1,20.0))self.update()defmousePressEvent(self,event):ifevent.button()==Qt.LeftButtonandself._pixmapisnotNone:self._dragging=Trueself._last_pos=event.position().toPoint()self.setCursor(Qt.ClosedHandCursor)super().mousePressEvent(event)defmouseMoveEvent(self,event):ifself._draggingandself._pixmapisnotNone:cur=event.position().toPoint()delta=cur-self._last_pos self._last_pos=cur self._offset+=delta self.update()super().mouseMoveEvent(event)defmouseReleaseEvent(self,event):ifevent.button()==Qt.LeftButton:self._dragging=Falseself.setCursor(Qt.ArrowCursor)super().mouseReleaseEvent(event)defmouseDoubleClickEvent(self,event):self._scale=1.0self._offset=QPoint(0,0)self.update()super().mouseDoubleClickEvent(event)defpaintEvent(self,event):super().paintEvent(event)ifself._pixmapisNone:returnpainter=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
