当前位置: 首页 > news >正文

YOLO11解决方案之对象裁剪探索

概述

Ultralytics提供了一系列的解决方案,利用YOLO11解决现实世界的问题,包括物体计数、模糊处理、热力图、安防系统、速度估计、物体追踪等多个方面的应用。

对象裁剪是指从图像或视频中分离并提取特定的检测对象,YOLO11 模型功能可用于准确识别和划分物体,从而实现精确裁剪,以便进一步分析或处理。使用YOLO11 可以方便的对目标对象进行裁剪,可对场景中的单个项目进行深入检查或处理,同时可以显著降低数据量,方便传输和存储。

演示代码

Ultralytics提供了演示代码,展示如何使用距离计算解决方案。

import cv2from ultralytics import solutionscap = cv2.VideoCapture("path/to/video.mp4")
assert cap.isOpened(), "Error reading video file"# Initialize object cropper object
cropper = solutions.ObjectCropper(model="yolo11n.pt",  # model for object cropping i.e yolo11x.pt.classes=[0, 2],  # crop specific classes i.e. person and car with COCO pretrained model.# conf=0.5,  # adjust confidence threshold for the objects.# crop_dir="cropped-detections",  # set the directory name for cropped detections
)# Process video
while cap.isOpened():success, im0 = cap.read()if not success:print("Video frame is empty or processing is complete.")breakresults = cropper(im0)# print(results)  # access the outputcap.release()
cv2.destroyAllWindows()  # destroy all opened windows

ObjectCropper参数

基本参数

参数类型默认值说明
modelstrNoneUltralytics YOLO 模型文件的路径。
crop_dirstr"cropped-detections"用于存储裁剪检测数据的目录名称。

可视化参数:

参数类型默认值说明
showboolFalse在这个方案中,show参数没有作用。

工作原理

ObjectCropper 类的工作原理是对图像中被检测到的物体,根据边框信息,裁剪下来,并保存为独立的图像文件。这个类比较简单。

class ObjectCropper(BaseSolution):"""这个类继承自BaseSolution类,根据检测到的边框,把物体裁剪下来保存为独立的文件。Attributes:crop_dir (str): 指定裁剪图片的保存路径crop_idx (int): 裁剪对象的数据iou (float): IoU阈值.conf (float): 置信度阈值.Methods:process: 对输入的图像中的检测物体进行裁剪并保存def __init__(self, **kwargs):super().__init__(**kwargs)self.crop_dir = self.CFG["crop_dir"]  # Directory for storing cropped detectionsif not os.path.exists(self.crop_dir):os.mkdir(self.crop_dir)  # Create directory if it does not existif self.CFG["show"]:self.LOGGER.warning(f"show=True disabled for crop solution, results will be saved in the directory named: {self.crop_dir}")self.crop_idx = 0  # Initialize counter for total cropped objectsself.iou = self.CFG["iou"]self.conf = self.CFG["conf"]def process(self, im0):results = self.model.predict(im0, classes=self.classes, conf=self.conf, iou=self.iou, device=self.CFG["device"])[0]for box in results.boxes:self.crop_idx += 1save_one_box(box.xyxy,im0,file=Path(self.crop_dir) / f"crop_{self.crop_idx}.jpg",BGR=True,)# Return SolutionResultsreturn SolutionResults(plot_im=im0, total_crop_objects=self.crop_idx)

效果展示

这里使用演示代码和测试视频,展示裁剪的物体图片。
请添加图片描述
请添加图片描述

裁剪图片保存在指定目录下:
请添加图片描述

http://www.xdnf.cn/news/484795.html

相关文章:

  • 大模型崛起:从技术突破到产业变革的深度解析
  • 【node】中间件
  • MySQL基础面试通关秘籍(附高频考点解析)
  • Promise.all 详解
  • java后端学习
  • 高效率者的特点
  • 三毛电视 1.0 | 央视、卫视、港澳台频道高清秒播,支持多种播放模式和电视投屏
  • C#数组与集合
  • 启用rvzi可视化自己的机器人发现joint state publisher gui没有滑块
  • Python多线程实战:提升并发效率的秘诀
  • 面向复杂环境的高性能通信接口芯片技术解析与应用
  • onvif支持H265
  • AI日报 · 2025年05月16日|Google DeepMind推出AlphaEvolve,能自主设计高级算法的编码代理
  • NFS服务
  • 【洗车店专用软件】佳易王洗车店多项目会员管理系统:一卡多用扣次软件系统实操教程 #扣次洗车管理软件
  • AUTOSAR图解==>AUTOSAR_SWS_ICUDriver_AUTOSAR_SWS_ICUDriver
  • matlab求解问题
  • 14、Python时间表示:Unix时间戳、毫秒微秒精度与time模块实战
  • Day 27 函数专题2 装饰器
  • 读取toml, 合并,生成新文件
  • Apollo Client 1.6.0 + @RefreshScope + @Value 刷新问题解析
  • volatile关键字详解
  • 淘宝商家层级存在流量上限怎么办,如何突破流量上限?
  • 梁文锋署名,DeepSeek-V3新论文揭秘:低成本大模型训练如何突破算力瓶颈?
  • 养生:健康生活的极简密码
  • P21-RNN-心脏病预测
  • blender中旋转模型,导入到threejs中带了旋转信息
  • Java与C/C++跨平台互操作深度解析:Project Panama技术实战
  • 一种应用非常广泛的开源RTOS(实时操作系统):nuttx
  • Spring Security vs Shiro vs Sa-Token