開源 python 應用 開發(五)python opencv之目標檢測

?最近有個項目需要做視覺自動化處理的工具,最后選用的軟件為python,剛好這個機會進行系統學習。短時間學習,需要快速開發,所以記錄要點步驟,防止忘記。

?鏈接:

開源 python 應用 開發(一)python、pip、pyAutogui、python opencv安裝-CSDN博客

開源 python 應用 開發(二)基于pyautogui、open cv 視覺識別的工具自動化-CSDN博客

開源 python 應用 開發(三)python語法介紹-CSDN博客

開源 python 應用 開發(四)python文件和系統綜合應用-CSDN博客

?推薦鏈接:

開源 Arkts 鴻蒙應用 開發(一)工程文件分析-CSDN博客

開源 Arkts 鴻蒙應用 開發(二)封裝庫.har制作和應用-CSDN博客

開源 Arkts 鴻蒙應用 開發(三)Arkts的介紹-CSDN博客

開源 Arkts 鴻蒙應用 開發(四)布局和常用控件-CSDN博客

開源 Arkts 鴻蒙應用 開發(五)控件組成和復雜控件-CSDN博客

?推薦鏈接:

開源 java android app 開發(一)開發環境的搭建-CSDN博客

開源 java android app 開發(二)工程文件結構-CSDN博客

開源 java android app 開發(三)GUI界面布局和常用組件-CSDN博客

開源 java android app 開發(四)GUI界面重要組件-CSDN博客

開源 java android app 開發(五)文件和數據庫存儲-CSDN博客

開源 java android app 開發(六)多媒體使用-CSDN博客

開源 java android app 開發(七)通訊之Tcp和Http-CSDN博客

開源 java android app 開發(八)通訊之Mqtt和Ble-CSDN博客

開源 java android app 開發(九)后臺之線程和服務-CSDN博客

開源 java android app 開發(十)廣播機制-CSDN博客

開源 java android app 開發(十一)調試、發布-CSDN博客

開源 java android app 開發(十二)封庫.aar-CSDN博客

推薦鏈接:

開源C# .net mvc 開發(一)WEB搭建_c#部署web程序-CSDN博客

開源 C# .net mvc 開發(二)網站快速搭建_c#網站開發-CSDN博客

開源 C# .net mvc 開發(三)WEB內外網訪問(VS發布、IIS配置網站、花生殼外網穿刺訪問)_c# mvc 域名下不可訪問內網,內網下可以訪問域名-CSDN博客

開源 C# .net mvc 開發(四)工程結構、頁面提交以及顯示_c#工程結構-CSDN博客

開源 C# .net mvc 開發(五)常用代碼快速開發_c# mvc開發-CSDN博客

本章節內容如下:實現了使用 YOLOv3 (You Only Look Once version 3) 深度學習模型進行目標檢測的功能。識別了香蕉、手機、夜景中的汽車和行人,第一次玩感覺挺有意思的。對圖片有些要求自己更換圖片,最好選高清大圖。

1.??YOLOv3 模型

2.? 主要函數

3.? 所有代碼

4.? 效果演示

一、YOLOv3 模型

使用預訓練的 YOLOv3 模型(需要 yolov3.cfg 和 yolov3.weights 文件)

基于 COCO 數據集(80 個類別)

這個代碼需要3個文件,分別是yolov3.cfg、yolov3.weights、coco.names網上很容易能搜到。

更換對應的 .cfg文件和.weights文件

鏈接:YOLO: Real-Time Object Detection

yolov3.cfg文件

[net]
# Testing
# batch=1
# subdivisions=1
# Training
batch=64
subdivisions=16
width=608
height=608
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky# Downsample[convolutional]
batch_normalize=1
filters=64
size=3
stride=2
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=32
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear# Downsample[convolutional]
batch_normalize=1
filters=128
size=3
stride=2
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear# Downsample[convolutional]
batch_normalize=1
filters=256
size=3
stride=2
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear# Downsample[convolutional]
batch_normalize=1
filters=512
size=3
stride=2
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear# Downsample[convolutional]
batch_normalize=1
filters=1024
size=3
stride=2
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky[shortcut]
from=-3
activation=linear######################[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear[yolo]
mask = 6,7,8
anchors = 10,13,  16,30,  33,23,  30,61,  62,45,  59,119,  116,90,  156,198,  373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1[route]
layers = -4[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[upsample]
stride=2[route]
layers = -1, 61[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear[yolo]
mask = 3,4,5
anchors = 10,13,  16,30,  33,23,  30,61,  62,45,  59,119,  116,90,  156,198,  373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1[route]
layers = -4[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[upsample]
stride=2[route]
layers = -1, 36[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear[yolo]
mask = 0,1,2
anchors = 10,13,  16,30,  33,23,  30,61,  62,45,  59,119,  116,90,  156,198,  373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

coco.names文件

person
bicycle
car
motorbike
aeroplane
bus
train
truck
boat
traffic light
fire hydrant
stop sign
parking meter
bench
bird
cat
dog
horse
sheep
cow
elephant
bear
zebra
giraffe
backpack
umbrella
handbag
tie
suitcase
frisbee
skis
snowboard
sports ball
kite
baseball bat
baseball glove
skateboard
surfboard
tennis racket
bottle
wine glass
cup
fork
knife
spoon
bowl
banana
apple
sandwich
orange
broccoli
carrot
hot dog
pizza
donut
cake
chair
sofa
pottedplant
bed
diningtable
toilet
tvmonitor
laptop
mouse
remote
keyboard
cell phone
microwave
oven
toaster
sink
refrigerator
book
clock
vase
scissors
teddy bear
hair drier
toothbrush

二、主要函數

2.1??load_yolo() 函數

功能:加載 YOLOv3 模型和相關文件

def load_yolo():# 獲取當前目錄current_dir = os.path.dirname(os.path.abspath(__file__))# 構建完整路徑cfg_path = os.path.join(current_dir, "yolov3.cfg")weights_path = os.path.join(current_dir, "yolov3.weights")names_path = os.path.join(current_dir, "coco.names")# 檢查文件是否存在if not all(os.path.exists(f) for f in [cfg_path, weights_path, names_path]):raise FileNotFoundError("缺少YOLO模型文件,請確保yolov3.cfg、yolov3.weights和coco.names在腳本目錄下")# 加載網絡net = cv2.dnn.readNet(weights_path, cfg_path)with open(names_path, "r") as f:classes = [line.strip() for line in f.readlines()]layer_names = net.getLayerNames()output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]return net, classes, output_layers

2.2??detect_objects(img, net, output_layers) 函數

功能:對輸入圖像進行目標檢測

def detect_objects(img, net, output_layers):# 從圖像創建blobblob = cv2.dnn.blobFromImage(img, scalefactor=1/255.0, size=(416, 416), swapRB=True, crop=False)# 設置輸入并進行前向傳播net.setInput(blob)outputs = net.forward(output_layers)return outputs

2.3??get_box_dimensions(outputs, height, width) 函數

功能:處理網絡輸出,提取邊界框信息

def get_box_dimensions(outputs, height, width):boxes = []confidences = []class_ids = []for output in outputs:for detection in output:scores = detection[5:]class_id = np.argmax(scores)confidence = scores[class_id]if confidence > 0.5:  # 置信度閾值# 計算邊界框坐標center_x = int(detection[0] * width)center_y = int(detection[1] * height)w = int(detection[2] * width)h = int(detection[3] * height)# 矩形左上角坐標x = int(center_x - w / 2)y = int(center_y - h / 2)boxes.append([x, y, w, h])confidences.append(float(confidence))class_ids.append(class_id)return boxes, confidences, class_ids

2.4???draw_labels(boxes, confidences, class_ids, classes, img) 函數

功能:在圖像上繪制檢測結果

def draw_labels(boxes, confidences, class_ids, classes, img):# 應用非極大值抑制indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)# 設置顏色colors = np.random.uniform(0, 255, size=(len(classes), 3))if len(indexes) > 0:for i in indexes.flatten():x, y, w, h = boxes[i]label = str(classes[class_ids[i]])confidence = str(round(confidences[i], 2))color = colors[class_ids[i]]# 繪制邊界框和標簽cv2.rectangle(img, (x, y), (x + w, y + h), color, 2)cv2.putText(img, f"{label} {confidence}", (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)return img

2.5??object_detection(image_path) 函數

功能:主函數,整合整個檢測流程

def object_detection(image_path):try:net, classes, output_layers = load_yolo()img = cv2.imread(image_path)if img is None:raise FileNotFoundError(f"無法加載圖像: {image_path}")height, width = img.shape[:2]outputs = detect_objects(img, net, output_layers)boxes, confidences, class_ids = get_box_dimensions(outputs, height, width)img = draw_labels(boxes, confidences, class_ids, classes, img)cv2.imshow("Object Detection", img)cv2.waitKey(0)cv2.destroyAllWindows()except Exception as e:print(f"發生錯誤: {str(e)}")

三、所有代碼

import cv2
import numpy as np
import osdef load_yolo():# 獲取當前目錄current_dir = os.path.dirname(os.path.abspath(__file__))# 構建完整路徑cfg_path = os.path.join(current_dir, "yolov3.cfg")weights_path = os.path.join(current_dir, "yolov3.weights")names_path = os.path.join(current_dir, "coco.names")# 檢查文件是否存在if not all(os.path.exists(f) for f in [cfg_path, weights_path, names_path]):raise FileNotFoundError("缺少YOLO模型文件,請確保yolov3.cfg、yolov3.weights和coco.names在腳本目錄下")# 加載網絡net = cv2.dnn.readNet(weights_path, cfg_path)with open(names_path, "r") as f:classes = [line.strip() for line in f.readlines()]layer_names = net.getLayerNames()output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]return net, classes, output_layersdef detect_objects(img, net, output_layers):# 從圖像創建blobblob = cv2.dnn.blobFromImage(img, scalefactor=1/255.0, size=(416, 416), swapRB=True, crop=False)# 設置輸入并進行前向傳播net.setInput(blob)outputs = net.forward(output_layers)return outputsdef get_box_dimensions(outputs, height, width):boxes = []confidences = []class_ids = []for output in outputs:for detection in output:scores = detection[5:]class_id = np.argmax(scores)confidence = scores[class_id]if confidence > 0.5:  # 置信度閾值# 計算邊界框坐標center_x = int(detection[0] * width)center_y = int(detection[1] * height)w = int(detection[2] * width)h = int(detection[3] * height)# 矩形左上角坐標x = int(center_x - w / 2)y = int(center_y - h / 2)boxes.append([x, y, w, h])confidences.append(float(confidence))class_ids.append(class_id)return boxes, confidences, class_idsdef draw_labels(boxes, confidences, class_ids, classes, img):# 應用非極大值抑制indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)# 設置顏色colors = np.random.uniform(0, 255, size=(len(classes), 3))if len(indexes) > 0:for i in indexes.flatten():x, y, w, h = boxes[i]label = str(classes[class_ids[i]])confidence = str(round(confidences[i], 2))color = colors[class_ids[i]]# 繪制邊界框和標簽cv2.rectangle(img, (x, y), (x + w, y + h), color, 2)cv2.putText(img, f"{label} {confidence}", (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)return imgdef object_detection(image_path):try:net, classes, output_layers = load_yolo()img = cv2.imread(image_path)if img is None:raise FileNotFoundError(f"無法加載圖像: {image_path}")height, width = img.shape[:2]outputs = detect_objects(img, net, output_layers)boxes, confidences, class_ids = get_box_dimensions(outputs, height, width)img = draw_labels(boxes, confidences, class_ids, classes, img)cv2.imshow("Object Detection", img)cv2.waitKey(0)cv2.destroyAllWindows()except Exception as e:print(f"發生錯誤: {str(e)}")if __name__ == "__main__":# 使用示例image_path = "myimg.jpg"  # 替換為你的圖片路徑object_detection(image_path)

四、效果演示

4.1? 識別香蕉

4.2? 識別手機

4.3? 識別夜景中的汽車和人

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/88727.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/88727.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/88727.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ABP VNext + OpenTelemetry + Jaeger:分布式追蹤與調用鏈可視化

ABP VNext OpenTelemetry Jaeger:分布式追蹤與調用鏈可視化 🚀 📚 目錄ABP VNext OpenTelemetry Jaeger:分布式追蹤與調用鏈可視化 🚀背景與動機 🌟環境與依賴 📦必裝 NuGet 包系統架構概覽…

C語言中整數編碼方式(原碼、反碼、補碼)

在 C 語言中,原碼、反碼、補碼的運算規則與其編碼特性密切相關,核心差異體現在符號位是否參與運算、進位如何處理以及減法是否能轉化為加法等方面。以下是三者的運算規則及特點分析(以 8 位整數為例,符號位為最高位)&a…

js二維數組如何變為一維數組

在 JavaScript 中,將二維數組轉換為一維數組(扁平化)有多種方法,可根據數組結構復雜度、性能需求和兼容性選擇。以下是最常用的實現方式: 1. 使用 flat() 方法(ES2019) MDN釋義:flat…

Claude code在Windows上的配置流程

前言 昨天在服務器上配置好了 Claude code,發現其編碼性能和效率都非常不錯。 然而,嘗試用它修改帶 UI 界面的客戶端程序時頗為不便,因為服務器沒有圖形化界面,無法直接將應用界面直接顯示到開發機上,調試起來頗為不…

手把手教你用YOLOv10打造智能垃圾檢測系統

無需編程基礎!手把手教你用YOLOv10打造智能垃圾檢測系統 垃圾分類不再難,AI助手秒識別 你是否曾站在分類垃圾桶前猶豫不決?塑料瓶是可回收還是其他垃圾?外賣餐盒到底該丟哪里?隨著垃圾分類政策推廣,這樣的困…

batchnorm類

1. 偽代碼:2. python代碼:3. 測試:4. 加深理解:以 為例,x3,可見輸出的batchnorm后y0.2627.查看模型記錄的均值及方差,計算y0.286799,理解是大致這樣的計算過程。(為什么數…

SpringBoot項目保證接口冪等的五種方法!

1. 冪等概述 1.1 深入理解冪等性 在計算機領域中,冪等(Idempotence)是指任意一個操作的多次執行總是能獲得相同的結果,不會對系統狀態產生額外影響。在Java后端開發中,冪等性的實現通常通過確保方法或服務調用的結果…

SQL新手入門詳細教程和應用實例

SQL(Structured Query Language)是用于管理和操作關系型數據庫的標準語言。它允許你創建、查詢、更新和刪除數據。本教程將從基礎概念開始,逐步引導你上手SQL,并提供詳細的應用實例。教程基于標準SQL語法,實際使用時需根據數據庫系統(如MySQL、SQLite或PostgreSQL)調整。…

DVWA-LOW級-SQL手工注入漏洞測試(MySQL數據庫)+sqlmap自動化注入-小白必看(超詳細)

首次使用DVWA的靶場,咋們先從最低級別的LOW開始,因為之前玩過一下墨者學院,對sql注入有一點認識和理解,所以先從sql的盲注開始; 1、測試注入點是否存在sql注入的漏洞; (1)首先我們…

JAVA線程池詳解+學習筆記

1.線程池基礎概念線程池是一種資源復用技術,通過預先創建并管理一組線程,減少頻繁創建和銷毀線程的開銷。核心思想與數據庫連接池、字符串常量池類似,旨在提升系統性能。核心參數解析ThreadPoolExecutor構造函數包含7個關鍵參數:c…

數據分析庫 Pandas

對于Pandas的簡單認識和基本操作的練習一 介紹 Pandas 是一個開源的數據分析和數據處理庫,它是基于 Python 編程語言的庫。 Pandas 提供了易于使用的數據結構和數據分析工具,特別適用于處理結構化數據,如表格型數據(類似于 Excel …

qt 中不要讓 lambda 槽函數捕獲信號源對象的共享指針

錯誤示例std::shared_ptr<QSerialPort> serial{new QSerialPort{}};QSerialPort::connect(serial.get(),&QSerialPort::readyRead,[serial](){QByteArray receive_data serial->readAll();std::cout.write(receive_data.data(), receive_data.size());});這會直接…

Solidity 合約的編寫-完整開發流程:從編譯、測試、部署到交互

&#x1f9f1; Solidity 合約開發全流程&#xff08;Foundry 版&#xff09;? 適合對象&#xff1a;已經能寫合約但不清楚如何測試、部署、交互的開發者? 工具鏈&#xff1a;Foundry&#xff08;forge, anvil, cast&#xff09;&#x1f4cc; 開發流程總覽1?? 初始化項目 2…

設計模式 - 面向對象原則:SOLID最佳實踐

文章目錄深入理解 SOLID&#xff1a;用對原則&#xff0c;別把簡單問題搞復雜SOLID 原則概覽1. 單一職責原則&#xff08;SRP&#xff09;2. 開閉原則&#xff08;OCP&#xff09;3. 里氏替換原則&#xff08;LSP&#xff09;4. 接口隔離原則&#xff08;ISP&#xff09;5. 依賴…

Vue 3 中父組件內兩個子組件相互傳參的幾種方法

方法一&#xff1a;通過父組件中轉&#xff08;Props Emits&#xff09;<!-- ParentComponent.vue --> <template><ChildA :message-from-b"messageFromB" send-to-b"handleSendToB" /><ChildB :message-from-a"messageFromA&q…

三子棋游戲設計與實現(C 語言版)

一、需求分析目標&#xff1a;實現一個簡單的人機對戰三子棋&#xff0c;支持以下功能&#xff1a;初始化空棋盤&#xff0c;清晰展示落子狀態。玩家通過坐標落子&#xff08;X 代表玩家&#xff09;&#xff0c;電腦隨機落子&#xff08;O 代表電腦&#xff09;。實時判斷勝負…

GD32 CAN1和TIMER0同時開啟問題

背景&#xff1a;今天在一個項目調試的時候發現了一些問題&#xff0c;由此貼記錄一下問題解決的過程。使用的芯片是GD32F305VE。使用到了CAN1和TIMER0。在使用這連個外設的時候發送了一些問題。單獨使用CAN1。功能正常。單獨使用TIMER0。配置為輸出模式。功能正常。但是當兩個…

劍指offer56_數組中唯一只出現一次的數字

數組中唯一只出現一次的數字在一個數組中除了一個數字只出現一次之外&#xff0c;其他數字都出現了三次。 請找出那個只出現一次的數字。 你可以假設滿足條件的數字一定存在。 思考題&#xff1a; 如果要求只使用 O(n) 的時間和額外 O(1) 的空間&#xff0c;該怎么做呢&#xf…

從語音識別到智能助手:Voice Agent 的技術進化與交互變革丨Voice Agent 學習筆記

From Research AI&#xff1a; 最近看到 Andrew Ng 的一句話讓我印象深刻&#xff1a;“While some things in AI are overhyped, voice applications seem underhyped right now.”&#xff08;盡管 AI 中有些領域被過度炒作&#xff0c;語音應用卻似乎被低估了&#xff09;。…

什么是Jaccard 相似度(Jaccard Similarity)

文章目錄? 定義&#xff1a;&#x1f4cc; 取值范圍&#xff1a;&#x1f50d; 舉例說明&#xff1a;&#x1f9e0; 應用場景&#xff1a;?? 局限性&#xff1a;&#x1f4a1; 擴展概念&#xff1a;Jaccard 相似度&#xff08;Jaccard Similarity&#xff09; 是一種用于衡量…