国产精品久久久aaaa,日日干夜夜操天天插,亚洲乱熟女香蕉一区二区三区少妇,99精品国产高清一区二区三区,国产成人精品一区二区色戒,久久久国产精品成人免费,亚洲精品毛片久久久久,99久久婷婷国产综合精品电影,国产一区二区三区任你鲁

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

把YOLOv11和Python Qt做個用戶界面程序

安費諾傳感器學堂 ? 來源:安費諾傳感器學堂 ? 2024-11-28 10:18 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

早些時間,小編想把PID控制器優化部分通過Py Qt來實現用戶界面化,不過看著窗口一堆參數,有點發怵:這玩意誰用?。?/p>

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

參考《PID控制器參數自動優化示例和比較》

后來就擱置了。 在通過Python以及YOLO來檢測圖中或者視頻中的各種物體以及人物的時候,就會考慮:全部用代碼來輸出的?怎么通過一個簡單直觀的窗口界面來測試相應的功能?我覺得要再試一下,哪怕是最簡單的方式呈現。這便是這篇文章的目的所在。 我們通過YOLO現成的各種檢測模塊,實現:

圖中物體的識別檢測

檢出物體的區域分割

人體姿態的檢測

還有其他的檢測功能,感覺功能有重疊,就選了上面的三個功能簡單地集成到一個windows的因為分類的功能只是軟件界面中。 以下圖片均有AI生成,但是人體姿態檢測的結果可能看不清楚輸出。

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

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

[1]物體檢測

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

[2]物體分割

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

[3]姿態檢測

我們可以自己嘗試運行一下。

# 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 圖像檢測')
        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(['物體檢測', '物體分割', '人體姿態識別'])  # 假設在此處添加不同的YOLO任務
        control_layout.addWidget(self.yolo_combo)


        self.run_button = QPushButton('開始檢測', 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 =='物體檢測':
                #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 == '人體姿態識別':
                #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_())
小編甚至用它來檢測一個AI生成的油畫風格的圖片。看圖中哪些抽象的只有形態沒有細節的人和物體,居然仍然可以檢測出來。大家可以試一下看看檢測的結果。

代碼中涉及到的python軟件包,需要額外安裝,模型文件用的是YOLO現成的。小編把這個軟件用打包工具生成的exe文件,因為攘括的軟件多,簡單的這些功能,打包后的文件壓縮后的大小竟高達近900MB(分割壓縮工具要收費咯),而很多平臺不支持這么大的文件上傳,所以這里也無法提供打包后的文件下載鏈接。

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

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

是否在懷疑這個世界的真實性?用傳感器來檢測一下吧,這個世界的冷熱、正負壓,振動,周圍的空氣......可以負責任地告訴各位,我們還是碳基生物。

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 程序
    +關注

    關注

    117

    文章

    3846

    瀏覽量

    85225
  • PID控制器
    +關注

    關注

    2

    文章

    173

    瀏覽量

    19699
  • python
    +關注

    關注

    57

    文章

    4876

    瀏覽量

    90022

原文標題:把YOLOv11和Python Qt做個用戶界面程序

文章出處:【微信號:安費諾傳感器學堂,微信公眾號:安費諾傳感器學堂】歡迎添加關注!文章轉載請注明出處。

收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    直播 | 睿擎平臺AMP混合部署:你的Qt界面如何“指揮”底層電機?

    )晚8點,我們將通過一場直播,這些問題一次性講透。直播核心內容本次直播將以睿擎派RC3506J為硬件平臺,完整演示從Qt界面開發到底層電機驅動的全流程:1、Qt
    的頭像 發表于 03-03 19:33 ?253次閱讀
    直播 | 睿擎平臺AMP混合部署:你的<b class='flag-5'>Qt</b><b class='flag-5'>界面</b>如何“指揮”底層電機?

    直播預告 | 睿擎平臺AMP混合部署:你的Qt界面如何“指揮”底層電機?

    )晚8點,我們將通過一場直播,這些問題一次性講透。直播核心內容本次直播將以睿擎派RC3506J為硬件平臺,完整演示從Qt界面開發到底層電機驅動的全流程:1、Qt
    的頭像 發表于 02-27 18:18 ?148次閱讀
    直播預告 | 睿擎平臺AMP混合部署:你的<b class='flag-5'>Qt</b><b class='flag-5'>界面</b>如何“指揮”底層電機?

    RK3562 單板機圖形用戶界面開發完全手冊:Qt Creator 配置與 LVGL 案例詳解(二)

    程序自啟動與 GPU 加速實現。通過圖片顯示、LED 控制等案例,明確關鍵代碼與測試步驟。創龍科技以清晰實操指引,幫助開發者高效完成 Qt 圖形界面開發,適用于工業控制、智能終端等場景。
    的頭像 發表于 02-27 10:42 ?4905次閱讀
    RK3562 單板機圖形<b class='flag-5'>用戶</b><b class='flag-5'>界面</b>開發完全手冊:<b class='flag-5'>Qt</b> Creator 配置與 LVGL 案例詳解(二)

    RK3562 單板機圖形用戶界面開發完全手冊:Qt Creator 配置與 LVGL 案例詳解(一)

    程序自啟動與 GPU 加速實現。通過圖片顯示、LED 控制等案例,明確關鍵代碼與測試步驟。創龍科技以清晰實操指引,幫助開發者高效完成 Qt 圖形界面開發,適用于工業控制、智能終端等場景。
    的頭像 發表于 02-26 11:41 ?257次閱讀
    RK3562 單板機圖形<b class='flag-5'>用戶</b><b class='flag-5'>界面</b>開發完全手冊:<b class='flag-5'>Qt</b> Creator 配置與 LVGL 案例詳解(一)

    那些年我用OpenCV+Qt趟過哪些坑?寫給視覺應用開發者的避坑指南

    重寫半套程序。 11. 復雜場景:多路視頻實時檢測的界面與線程架構設計,以及如何用“讀寫者模式”管理共享數據,避免資源競爭。 第三階段:實戰 - 在真實項目中融會貫通 懂再多道理,不如親手實現一遍。我
    發表于 12-02 09:43

    RK3576 Yolov11訓練部署教程

    1.Yolo11簡介YOLO11系列是YOLO家族中最先進的(SOTA)、最輕量級、最高效的模型,其表現優于其前輩。它由Ultralytics創建,該組織發布了YOLOv8,這是迄今為止最穩定
    的頭像 發表于 07-25 15:22 ?1077次閱讀
    RK3576 <b class='flag-5'>Yolov11</b>訓練部署教程

    【Milk-V Duo S 開發板免費體驗】5 - 使用YOLOv11進行目標檢測

    引言 前面已經完成了Milk-V Duo S開發板的基本功能測試,今天來嘗試一下使用YOLOv11進行目標檢測。 TDL-SDK Cvitek 所提供的 TDL(Turnkey Deep
    發表于 07-24 14:57

    【HZ-RK3568開發板免費體驗】04 YOLOv11 模型轉換為RKNN并在板端部署

    程序自動將其保存為out.png,可以下載到電腦端查看,如下圖 至此,YOLOv11的模型轉換與部署就結束了,后面再研究視頻推理。
    發表于 07-02 14:01

    瑞芯微RK3506(3核A7@1.5GHz+雙網口+雙CAN-FD)工業開發板—圖形用戶界面(GUI)開發手冊

    本文主要說明Qt的圖形用戶界面(GUI)開發流程,包括Qt程序自啟動配置與案例介紹,旨在幫助開發者完成產品開發與測試。
    的頭像 發表于 06-03 14:27 ?1569次閱讀
    瑞芯微RK3506(3核A7@1.5GHz+雙網口+雙CAN-FD)工業開發板—圖形<b class='flag-5'>用戶</b><b class='flag-5'>界面</b>(GUI)開發手冊

    labview調用yolov8/11目標檢測、分割、分類

    labview使用2020版本64位編輯,調用yolov8/11的onnx模型案例。 源碼: 通過網盤分享的文件:Labview_cls.zip等4個文件 鏈接: https
    發表于 04-21 19:37

    【技術案例】Qt 環境部署 - Ubuntu 篇

    什么是Qt?Qt是一個跨平臺C++圖形用戶界面應用程序開發框架,可構建高性能的桌面、移動及Web應用程序
    的頭像 發表于 04-16 17:17 ?1921次閱讀
    【技術案例】<b class='flag-5'>Qt</b> 環境部署 - Ubuntu 篇

    RK3576 yolov11-seg訓練部署教程

    級的精確目標檢測與分割,適用于自動駕駛、醫學影像、工業檢測等對精度和速度要求苛刻的場景。 ? ? ? ?本教程針對目標分割算法yolov11 seg的訓練和部署到EASY-EAI-Orin-nano(RK3576)進行說明,而數據標注方法可以參考我們往期的文章。
    的頭像 發表于 04-16 09:43 ?2352次閱讀
    RK3576 <b class='flag-5'>yolov11</b>-seg訓練部署教程

    OrinNano yolov11訓練部署教程

    ORinNano yolov11訓練部署教程
    的頭像 發表于 04-10 15:26 ?2581次閱讀
    OrinNano  <b class='flag-5'>yolov11</b>訓練部署教程

    RK3576 Yolov11訓練部署教程

    YOLO11 系列是 YOLO 家族中最先進的 (SOTA)、最輕量級、最高效的模型,其表現優于其前輩。它由 Ultralytics 創建,該組織發布了 YOLOv8,這是迄今為止最穩定、使用最廣泛的 YOLO 變體。YOLO11
    的頭像 發表于 04-03 09:35 ?2016次閱讀
    RK3576 <b class='flag-5'>Yolov11</b>訓練部署教程

    Raspberry Pi上使用IR v11及OpenVINO? 2021.3后不兼容怎么辦?

    使用 Google Colab OpenVINO? 2022.2 將 yolov5 模型轉換為 IR v11: !git clone https://github.com/ultralytics
    發表于 03-06 07:14