소스 정보
- 저장소
- MIUAV/vibe-coding-ros2
- 최근 소스 활동
- 2026년 4월 3일 16:37
- 감지된 SKILL.md 언어
- 중국어
- 스타
- 26
- 포크
- 2
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/MIUAV/vibe-coding-ros2 --skill dnn-inference명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SKILL.md 표시 중
SOC 직업 분류 기준
| name | dnn-inference |
| description | OpenCV4 DNN 模块技能 - 神经网络推理、模型加载、ONNX、TFLite、Darknet 支持 |
| user-invocable | true |
| argument-hint | dnn OR 深度学习推理 OR onnx OR tflite OR tensorflow OR darknet |
OpenCV DNN 模块深度学习推理完整指南
当需要以下帮助时使用此技能:
| 框架 | OpenCV 支持 | 扩展名 |
|---|---|---|
| ONNX | ✓ | .onnx |
| TensorFlow | ✓ | .pb, .tflite |
| Caffe | ✓ | .caffemodel, .prototxt |
| Darknet | ✓ | .weights, .cfg |
| Torch | ✓ | .t7 |
| OpenVINO | ✓ | .xml, .bin |
import cv2
import numpy as np
# 加载模型
net = cv2.dnn.readNetFromONNX('model.onnx')
# 或 TensorFlow
net = cv2.dnn.readNetFromTensorflow('model.pb')
# 或 Darknet
net = cv2.dnn.readNetFromDarknet('model.weights', 'model.cfg')
# 设置后端和目标(使用 GPU)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
# 图像预处理
blob = cv2.dnn.blobFromImage(img, 1/255.0, (416, 416),
swapRB=True, crop=False)
# 推理
net.setInput(blob)
output = net.forward()
# 批量图像预处理
images = [cv2.imread(f) for f in image_files]
blob = cv2.dnn.blobFromImages(images, 1/255.0, (416, 416),
swapRB=True, crop=False)
# 批量推理
net.setInput(blob)
outputs = net.forward()
# 处理每个输出
for i, output in enumerate(outputs):
# output shape: [batch, classes, detections, 5+classes]
process_detection(output, images[i])
def postprocess_yolo(output, img_shape, conf_threshold=0.5, nms_threshold=0.4):
h, w = img_shape[:2]
boxes, confidences, class_ids = [], [], []
for detection in output:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
if confidence > conf_threshold:
cx, cy, bw, bh = detection[:4]
x = int((cx - bw/2) * w)
y = int((cy - bh/2) * h)
width = int(bw * w)
height = int(bh * h)
boxes.append([x, y, width, height])
confidences.append(float(confidence))
class_ids.append(class_id)
# NMS
indices = cv2.dnn.NMSBoxes(boxes, confidences, conf_threshold, nms_threshold)
return [(boxes[i], confidences[i], class_ids[i]) for i in indices.flatten()]
#include <opencv2/dnn.hpp>
#include <opencv2/dnn/all_layers.hpp>
using namespace cv::dnn;
// 加载模型
Net net = readNetFromONNX("model.onnx");
// Net net = readNetFromTensorflow("model.pb");
// Net net = readNetFromDarknet("model.weights", "model.cfg");
// 设置后端
net.setPreferableBackend(DNN_BACKEND_CUDA);
net.setPreferableTarget(DNN_TARGET_CUDA);
// 预处理
Mat blob = blobFromImage(img, 1/255.0, Size(416, 416),
Scalar(), true, false);
// 推理
net.setInput(blob);
Mat output = net.forward();
// 后处理
std::vector<int> classIds;
std::vector<float> confidences;
std::vector<Rect> boxes;
for (int i = 0; i < output.size[2]; i++) {
float confidence = output.at<float>(0, 0, i, 2);
if (confidence > 0.5) {
int classId = (int)output.at<float>(0, 0, i, 1);
int x = ()(output.<>(, , i, ) * img.cols);
y = ()(output.<>(, , i, ) * img.rows);
w = ()(output.<>(, , i, ) * img.cols);
h = ()(output.<>(, , i, ) * img.rows);
boxes.(x, y, w, h);
confidences.(confidence);
classIds.(classId);
}
}
std::vector<> indices;
(boxes, confidences, , , indices);
# CPU
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
# CUDA GPU
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
# OpenVINO
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
模型准备:
预处理优化:
blobFromImages 批量处理swapRB=True 处理 RGB/BGR 转换推理优化:
内存管理:
Mat 对象避免频繁分配release() 释放中间结果