在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

把YOLOv11和Python Qt做個(gè)用戶界面程序

安費(fèi)諾傳感器學(xué)堂 ? 來(lái)源:安費(fèi)諾傳感器學(xué)堂 ? 2024-11-28 10:18 ? 次閱讀

早些時(shí)間,小編想把PID控制器優(yōu)化部分通過(guò)Py Qt來(lái)實(shí)現(xiàn)用戶界面化,不過(guò)看著窗口一堆參數(shù),有點(diǎn)發(fā)怵:這玩意誰(shuí)用啊?

9e185014-a936-11ef-93f3-92fbcf53809c.png

參考《PID控制器參數(shù)自動(dòng)優(yōu)化示例和比較》

后來(lái)就擱置了。 在通過(guò)Python以及YOLO來(lái)檢測(cè)圖中或者視頻中的各種物體以及人物的時(shí)候,就會(huì)考慮:全部用代碼來(lái)輸出的?怎么通過(guò)一個(gè)簡(jiǎn)單直觀的窗口界面來(lái)測(cè)試相應(yīng)的功能?我覺(jué)得要再試一下,哪怕是最簡(jiǎn)單的方式呈現(xiàn)。這便是這篇文章的目的所在。 我們通過(guò)YOLO現(xiàn)成的各種檢測(cè)模塊,實(shí)現(xiàn):

圖中物體的識(shí)別檢測(cè)

檢出物體的區(qū)域分割

人體姿態(tài)的檢測(cè)

還有其他的檢測(cè)功能,感覺(jué)功能有重疊,就選了上面的三個(gè)功能簡(jiǎn)單地集成到一個(gè)windows的因?yàn)榉诸惖墓δ苤皇擒浖缑嬷小?以下圖片均有AI生成,但是人體姿態(tài)檢測(cè)的結(jié)果可能看不清楚輸出。

按照我們之前的慣例,先提供結(jié)果,后提供代碼。

9e83512a-a936-11ef-93f3-92fbcf53809c.png

[1]物體檢測(cè)

9eb9e1f4-a936-11ef-93f3-92fbcf53809c.png

[2]物體分割

9efb1868-a936-11ef-93f3-92fbcf53809c.png

[3]姿態(tài)檢測(cè)

我們可以自己嘗試運(yùn)行一下。

# This program is part of a project developed by Amphenol Sensors.
#Copyright(C)2024,Leo Lu
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .


import sys
from PyQt5.QtWidgets import (QApplication, QLabel, QPushButton, QVBoxLayout, QWidget, 
                             QFileDialog, QComboBox, QHBoxLayout)
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtCore import Qt
import cv2
import numpy as np
import random


from ultralytics import YOLO
from ultralytics.models.yolo.pose.predict import PosePredictor


class YOLOInterface(QWidget):
    def __init__(self):
        super().__init__()


        self.initUI()
        self.model_detec = YOLO('./yolo_models/yolo11s.pt')
        self.model_seg = YOLO('./yolo_models/yolo11s-seg.pt')
        self.model_bd = './yolo_models/yolo11s-pose.pt'
        self.connections = ((2, 4), (1, 3), (10, 8), (8, 6), (6, 5), (5, 7), (7, 9), 
                            (6, 12), (12, 14), (14, 16), (5, 11), (11, 13), (13, 15))


    def initUI(self):
        self.setWindowTitle('YOLO 圖像檢測(cè)')
        self.setGeometry(100, 100, 1200, 600)
        self.setFixedSize(1200, 600)
        # 主布局
        main_layout = QVBoxLayout()


        # 圖像顯示布局
        image_layout = QHBoxLayout()


        self.image_label = QLabel(self)
        self.image_label.setFixedSize(600, 400)
        self.image_label.setAlignment(Qt.AlignCenter)
        image_layout.addWidget(self.image_label)


        self.result_label = QLabel(self)
        self.result_label.setFixedSize(600, 400)
        self.result_label.setAlignment(Qt.AlignCenter)
        image_layout.addWidget(self.result_label)


        main_layout.addLayout(image_layout)


        # 控制布局
        control_layout = QHBoxLayout()


        self.detect_button = QPushButton('選擇圖片', self)
        self.detect_button.clicked.connect(self.load_image)
        control_layout.addWidget(self.detect_button)


        self.yolo_combo = QComboBox(self)
        self.yolo_combo.addItems(['物體檢測(cè)', '物體分割', '人體姿態(tài)識(shí)別'])  # 假設(shè)在此處添加不同的YOLO任務(wù)
        control_layout.addWidget(self.yolo_combo)


        self.run_button = QPushButton('開(kāi)始檢測(cè)', self)
        self.run_button.clicked.connect(self.run_yolo)
        control_layout.addWidget(self.run_button)


        self.quit_button = QPushButton('退出', self)
        self.quit_button.clicked.connect(self.close_application)
        control_layout.addWidget(self.quit_button)


        main_layout.addLayout(control_layout)
        self.setLayout(main_layout)


    def load_image(self):
        options = QFileDialog.Options()
        file_name, _ = QFileDialog.getOpenFileName(self, "選擇圖片文件", "", "Images (*.png *.jpg *.bmp)", options=options)
        if file_name:
            self.current_image = file_name
            pixmap = QPixmap(file_name)
            scaled_pixmap = pixmap.scaled(self.image_label.size(), Qt.KeepAspectRatio)
            self.image_label.setPixmap(scaled_pixmap)


    def plot_keypoints(self, image, keypoints, line_color=(60, 179, 113), point_color=(255, 0, 0),
                   offset=(0, 0), show_idx=False):
        if keypoints is None:
            return image
        
        for data in keypoints.xy:
            if len(data) == 0:
                continue
            # Draw connections between keypoints
            for start_index, end_index in self.connections:
                start_point, end_point = data[start_index], data[end_index]
                if all(start_point[:2] > 0) and all(end_point[:2] > 0):  # Ignore invalid points
                    cv2.line(image, 
                             tuple(map(lambda v, o: int(v + o), start_point[:2], offset)), 
                             tuple(map(lambda v, o: int(v + o), end_point[:2], offset)), 
                             line_color, 2)
            # Draw keypoints
            for index, (x, y) in enumerate(data[:, :2]):
                if x > 0 or y > 0:  # Ignore invalid points
                    cv2.circle(image, 
                               (int(x + offset[0]), int(y + offset[1])), 
                               5, point_color, -1)
                    if show_idx:
                        cv2.putText(image, 
                                    str(index), 
                                    (int(x + offset[0]), int(y + offset[1])), 
                                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, point_color, 1, cv2.LINE_AA)
    
        return image


    def run_yolo(self):
        if hasattr(self, 'current_image'):
            img = cv2.imread(self.current_image)
            
            # YOLO推理示例:
            task = self.yolo_combo.currentText()
            if task =='物體檢測(cè)':
                #model = self.model_detec #YOLO('yolo11s.pt')
                results = self.model_detec(img)
                
                for result in results:
                    boxes = result.boxes                # Pseudo-code; adjust based on actual library


                    for box in boxes:
                        x1, y1, x2, y2 = box.xyxy[0]    # Extracting the bounding box coordinates
                        class_name = self.model_detec.names[int(box.cls[0])]  # Using class_id to get class_name from model
                        confidence = box.conf.item()
                        cv2.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 2)
                        txt_y_pos = int(y1) - 10
                        if txt_y_pos <= 10:
                            txt_y_pos = int(y2) - 10
                        
                        class_name = class_name + " "+ "{:.2g}".format(confidence)
                        cv2.putText(img, class_name, (int(x1), txt_y_pos), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)


            elif task =='物體分割':
                #model = YOLO('yolo11s-seg.pt')
                results = self.model_seg(img)
                
                # Prepare an overlay image with the same dimensions
                overlay = img.copy()
                
                for result in results:
                    boxes = result.boxes  # Pseudo-code; adjust based on actual library
                    masks = result.masks
                    names = result.names
                    for box, mask in zip(boxes, masks):
                        for cls, contour in zip(box.cls, mask.xy):
                            class_id = cls.item()  # Get scalar from tensor
                            class_name = names[class_id]
                            #print(class_name)
                            #print(cv2.contourArea(contour))  # Calculate contour area
                            
                            # Generate a random color
                            color = [random.randint(0, 255) for _ in range(3)]
                            
                            # Fill the contour on the overlay with the random color
                            cv2.drawContours(overlay, [contour.astype(np.int32)], -1, color, thickness=cv2.FILLED)
                # Define the alpha (transparency factor)
                alpha = 0.4  # Value between 0 (transparent) and 1 (opaque)
                
                # Blend the overlay with the original image
                """
                Parameters
                overlay (src1):


                This is the first input array (image).
                In your context, this represents the overlay image, which typically contains modifications like semi-transparent masks drawn over contours.
                
                alpha:
                This is the weight of the first array (image).
                It controls the opacity of the overlay. A value closer to 1 makes the overlay more prominent, while a value closer to 0 makes it less prominent.
                
                img (src2):
                This is the second input array (image).
                It represents the original image onto which the overlay is being applied.
                
                1 - alpha (beta):
                This is the weight of the second array (image).
                Complementary to alpha, it controls the visibility of the original image. A value closer to 1 makes the original image more visible, while closer to 0 makes it less visible.
                
                0 (gamma):
                A scalar added to each sum.
                Typically set to 0 when blending for direct overlay purposes without additional brightness adjustment.
                
                img (dst):
                The destination array where the output is stored.
                It uses the same variable as the original image, implying that the blended result will overwrite this variable.
                """
                cv2.addWeighted(overlay, alpha, img, 1 - alpha, 0, img)


            elif task == '人體姿態(tài)識(shí)別':
                #model = YOLO('yolo11s-pose.pt')
                #results = model(img)
                
                overrides_Body_pose = {
                    "task": "pose",
                    "mode": "predict",
                    "model": self.model_bd,        #'yolo11s-pose.pt'
                    "verbose": False,
                    "classes": [0],
                    "iou": 0.5,
                    "conf": 0.3
                    }


                predictor_ren_pose = PosePredictor(overrides=overrides_Body_pose)
                pose_ren = predictor_ren_pose(img)[0]
                
                img = self.plot_keypoints(img, pose_ren.keypoints)
                
            # Convert the image to a format suitable for PyQt
            height, width, channel = img.shape
            bytes_per_line = 3 * width
            q_image = QImage(img.data, width, height, bytes_per_line, QImage.Format_RGB888).rgbSwapped()
            pixmap = QPixmap.fromImage(q_image)
            self.display_results(pixmap)


    def display_results(self, pixmap):
        scaled_pixmap = pixmap.scaled(self.result_label.size(), Qt.KeepAspectRatio)
        self.result_label.setPixmap(scaled_pixmap)


    def close_application(self):
        self.close()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = YOLOInterface()
    ex.show()
    sys.exit(app.exec_())
小編甚至用它來(lái)檢測(cè)一個(gè)AI生成的油畫(huà)風(fēng)格的圖片。看圖中哪些抽象的只有形態(tài)沒(méi)有細(xì)節(jié)的人和物體,居然仍然可以檢測(cè)出來(lái)。大家可以試一下看看檢測(cè)的結(jié)果。

代碼中涉及到的python軟件包,需要額外安裝,模型文件用的是YOLO現(xiàn)成的。小編把這個(gè)軟件用打包工具生成的exe文件,因?yàn)槿晾ǖ能浖啵?jiǎn)單的這些功能,打包后的文件壓縮后的大小竟高達(dá)近900MB(分割壓縮工具要收費(fèi)咯),而很多平臺(tái)不支持這么大的文件上傳,所以這里也無(wú)法提供打包后的文件下載鏈接。

9f681a44-a936-11ef-93f3-92fbcf53809c.png

視線收回,我們心曠神怡一下。感謝AI的提供。

是否在懷疑這個(gè)世界的真實(shí)性?用傳感器來(lái)檢測(cè)一下吧,這個(gè)世界的冷熱、正負(fù)壓,振動(dòng),周圍的空氣......可以負(fù)責(zé)任地告訴各位,我們還是碳基生物。

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 程序
    +關(guān)注

    關(guān)注

    117

    文章

    3797

    瀏覽量

    81456
  • PID控制器
    +關(guān)注

    關(guān)注

    2

    文章

    173

    瀏覽量

    18681
  • python
    +關(guān)注

    關(guān)注

    56

    文章

    4809

    瀏覽量

    85070

原文標(biāo)題:把YOLOv11和Python Qt做個(gè)用戶界面程序

文章出處:【微信號(hào):安費(fèi)諾傳感器學(xué)堂,微信公眾號(hào):安費(fèi)諾傳感器學(xué)堂】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏

    評(píng)論

    相關(guān)推薦

    RK3568國(guó)產(chǎn)芯教學(xué)實(shí)驗(yàn)箱:指紋識(shí)別實(shí)戰(zhàn)案例

    )GUI的設(shè)計(jì)實(shí)現(xiàn):LCD顯示界面以及與用戶的交互;(3)編輯控制代碼;(4)編譯程序;(5)運(yùn)行程序Qt
    的頭像 發(fā)表于 01-08 19:05 ?341次閱讀
    RK3568國(guó)產(chǎn)芯教學(xué)實(shí)驗(yàn)箱:指紋識(shí)別實(shí)戰(zhàn)案例

    基于QT開(kāi)發(fā)國(guó)產(chǎn)主板終端桌面程序 高效、穩(wěn)定、跨平臺(tái)的解決方案

    了開(kāi)發(fā)者們面臨的一個(gè)重要挑戰(zhàn)。本文將介紹如何基于QT框架,開(kāi)發(fā)適用于國(guó)產(chǎn)主板的終端桌面程序,并探討其優(yōu)勢(shì)和應(yīng)用場(chǎng)景。 QT是一個(gè)跨平臺(tái)的C++圖形用戶
    的頭像 發(fā)表于 01-08 15:34 ?202次閱讀

    在RK3568教學(xué)實(shí)驗(yàn)箱上實(shí)現(xiàn)基于YOLOV5的算法物體識(shí)別案例詳解

    安裝了所有必要的依賴。這通常包括 torch、torchvision 和 opencv-python。 (2)下載預(yù)訓(xùn)練模型 YOLOv5 提供了多個(gè)預(yù)訓(xùn)練模型,可以從官方倉(cāng)庫(kù)或相關(guān)資源中下載。 (3
    發(fā)表于 12-03 14:56

    國(guó)產(chǎn)處理器RK3568教學(xué)實(shí)驗(yàn)箱實(shí)操指南:直流電機(jī)控制

    一、實(shí)驗(yàn)?zāi)康?、熟悉Qt程序的開(kāi)發(fā)流程。2、掌握QtCreator的基礎(chǔ)開(kāi)發(fā)使用。3、通過(guò)編寫(xiě)Qt程序實(shí)現(xiàn)直流電機(jī)控制的顯示界面。二、實(shí)驗(yàn)原
    的頭像 發(fā)表于 11-22 01:08 ?471次閱讀
    國(guó)產(chǎn)處理器RK3568教學(xué)實(shí)驗(yàn)箱實(shí)操指南:直流電機(jī)控制

    YOLOv6在LabVIEW中的推理部署(含源碼)

    YOLOv6 是美團(tuán)視覺(jué)智能部研發(fā)的一款目標(biāo)檢測(cè)框架,致力于工業(yè)應(yīng)用。如何使用python進(jìn)行該模型的部署,官網(wǎng)已經(jīng)介紹的很清楚了,但是對(duì)于如何在LabVIEW中實(shí)現(xiàn)該模型的部署,筆者目前還沒(méi)有看到
    的頭像 發(fā)表于 11-06 16:07 ?427次閱讀
    <b class='flag-5'>YOLOv</b>6在LabVIEW中的推理部署(含源碼)

    國(guó)產(chǎn)Cortex-A55實(shí)驗(yàn)箱操作案例分享:LED程序開(kāi)發(fā)

    一、實(shí)驗(yàn)?zāi)康模?)熟悉Qt程序的開(kāi)發(fā)流程。(2)掌握QtCreator的基礎(chǔ)開(kāi)發(fā)使用。(3)通過(guò)編寫(xiě)Qt程序實(shí)現(xiàn)LED控制的顯示界面。二、實(shí)
    的頭像 發(fā)表于 11-01 08:10 ?215次閱讀
    國(guó)產(chǎn)Cortex-A55實(shí)驗(yàn)箱操作案例分享:LED<b class='flag-5'>程序</b>開(kāi)發(fā)

    EtherCAT運(yùn)動(dòng)控制器上位機(jī)開(kāi)發(fā)之Python+Qt(三):PDO配置與SDO讀寫(xiě)

    PC上位機(jī)Python+Qt混合編程實(shí)現(xiàn)PDO配置與SDO讀寫(xiě)
    的頭像 發(fā)表于 08-21 15:56 ?1258次閱讀
    EtherCAT運(yùn)動(dòng)控制器上位機(jī)開(kāi)發(fā)之<b class='flag-5'>Python+Qt</b>(三):PDO配置與SDO讀寫(xiě)

    嵌入式QT常見(jiàn)開(kāi)發(fā)方式有哪些?

    提供的豐富組件如按鈕、文本框、窗口等構(gòu)建傳統(tǒng)的桌面應(yīng)用風(fēng)格界面。對(duì)于嵌入式設(shè)備上的復(fù)雜用戶界面或者需要高性能響應(yīng)的應(yīng)用,Qt Widgets是一個(gè)較為常用的選擇。 2.
    發(fā)表于 08-12 10:05

    EtherCAT運(yùn)動(dòng)控制器上位機(jī)之Python+Qt(一):鏈接與單軸運(yùn)動(dòng)

    PC上位機(jī)Python+Qt混合編程,助力智能制造高效開(kāi)發(fā)。
    的頭像 發(fā)表于 07-31 09:43 ?504次閱讀
    EtherCAT運(yùn)動(dòng)控制器上位機(jī)之<b class='flag-5'>Python+Qt</b>(一):鏈接與單軸運(yùn)動(dòng)

    DongshanPI-AICT全志V853開(kāi)發(fā)板搭建YOLOV5-V6.0環(huán)境

    版 1.搭建Python環(huán)境 打開(kāi)Conda終端,創(chuàng)建Python3.7的Conda環(huán)境,輸入 conda create -n py37_yolov5 python=3.7 創(chuàng)建完成
    發(fā)表于 07-12 09:59

    上位機(jī)可視化界面編程軟件有哪些

    。以下是一些常見(jiàn)的上位機(jī)可視化界面編程軟件: Qt (跨平臺(tái)C++框架) 介紹 :Qt是一個(gè)跨平臺(tái)的C++圖形用戶界面應(yīng)用
    的頭像 發(fā)表于 06-06 10:48 ?2782次閱讀

    yolov5的best.pt導(dǎo)出成onnx轉(zhuǎn)化成fp32 bmodel后在Airbox上跑,報(bào)維度不匹配怎么處理?

    用官方的模型不出錯(cuò),用自己的yolov5訓(xùn)練出來(lái)的best.pt導(dǎo)出成onnx轉(zhuǎn)化成fp32 bmodel后在Airbox上跑,出現(xiàn)報(bào)錯(cuò): linaro@bm1684:~/yolov5/python
    發(fā)表于 05-31 08:10

    Qt Group與高通公司合作,簡(jiǎn)化工業(yè)物聯(lián)網(wǎng)的用戶界面開(kāi)發(fā)

    公司于當(dāng)?shù)貢r(shí)間4月9日宣布,正在合作為工業(yè)物聯(lián)網(wǎng)設(shè)備簡(jiǎn)化高級(jí)圖形用戶界面 (GUI) 的開(kāi)發(fā)和軟件質(zhì)量保證。 Qt Group與高通公司合作,簡(jiǎn)化工業(yè)物聯(lián)網(wǎng)的用戶
    的頭像 發(fā)表于 04-10 14:12 ?490次閱讀
    <b class='flag-5'>Qt</b> Group與高通公司合作,簡(jiǎn)化工業(yè)物聯(lián)網(wǎng)的<b class='flag-5'>用戶</b><b class='flag-5'>界面</b>開(kāi)發(fā)

    FPGA板子可以跑Qt應(yīng)用程序

    Qt作為一款跨平臺(tái)GUI圖形界面設(shè)計(jì)軟件,她可以在windows、Linux上運(yùn)行,沒(méi)聽(tīng)說(shuō)過(guò)在FPGA的板子上運(yùn)行Qt程序呢?
    發(fā)表于 03-28 23:27

    3562-Qt工程編譯說(shuō)明

    Qt 環(huán)境、交叉編譯 工具鏈等。當(dāng)用戶使用 Qt Creator 工具和 X86 端 Qt 環(huán)境編寫(xiě)并編譯 Qt 工程后,生成的
    的頭像 發(fā)表于 03-05 09:19 ?535次閱讀
    3562-<b class='flag-5'>Qt</b>工程編譯說(shuō)明
    主站蜘蛛池模板: 天天干天天曰天天操 | 亚洲热热久久九九精品 | 天堂网在线.www天堂在线 | 亚洲成a人片7777 | 在线视频一二三区 | 亚洲一区二区三区深夜天堂 | 国产做爰一区二区 | 亚洲丰满熟妇毛片在线播放 | 国产成人精品亚洲日本在线观看 | 天天干天天草天天 | 免费人成在线观看视频色 | 特黄特色大片免费视频大全 | a视频免费看 | 国产xxxxxx久色视频在 | 国产国产人免费人成免费视频 | 天天操天天干天天插 | 扒开双腿爽爽爽视频www | eeuss秋霞成人影院 | 免费人成网站永久 | 一级毛片真人免费观看 | 91精选视频在线观看 | 男男生子大肚play做到生 | cijilu刺激 国产| 天天躁狠狠躁夜夜躁2021 | aaaaaaa毛片| 欧美高清a | 日本三级网站在线线观看 | 久久久精品波多野结衣 | 日本成人在线网址 | 亚色图| 午夜免费观看 | 我不卡午夜 | 大美女久久久久久j久久 | 天天射日 | 性刺激的欧美三级视频 | 激情开心婷婷 | 天天碰天天干 | 四虎影院免费在线 | 男女全黄做爰视频 | 91桃色国产线观看免费 | 国产精品护士 |