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

给非吸公司建设网站广告资源发布平台

给非吸公司建设网站,广告资源发布平台,微网站制作,昆明房产网站建设TrackZone 使用Ultralytics YOLO11 -Ultralytics YOLO 文档 如何通过Ultralytics YOLO11 在Python 中使用 TrackZone? 只需几行代码,您就可以在特定区域设置对象跟踪,从而轻松将其集成到您的项目中。 import cv2from ultralytics import s…

TrackZone 使用Ultralytics YOLO11 -Ultralytics YOLO 文档

如何通过Ultralytics YOLO11 在Python 中使用 TrackZone?

只需几行代码,您就可以在特定区域设置对象跟踪,从而轻松将其集成到您的项目中。

import cv2from ultralytics import solutionscap = cv2.VideoCapture("path/to/video.mp4")
assert cap.isOpened(), "Error reading video file"
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))# Define region points
region_points = [(150, 150), (1130, 150), (1130, 570), (150, 570)]# Video writer
video_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))# Init trackzone (object tracking in zones, not complete frame)
trackzone = solutions.TrackZone(show=True,  # display the outputregion=region_points,  # pass region pointsmodel="yolo11n.pt",
)# Process video
while cap.isOpened():success, im0 = cap.read()if not success:print("Video frame is empty or video processing has been successfully completed.")breakresults = trackzone(im0)video_writer.write(results.plot_im)cap.release()
video_writer.release()
cv2.destroyAllWindows()

效果图:只检测一定范围内的人

部分相关库代码

# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/licenseimport cv2
import numpy as npfrom ultralytics.solutions.solutions import BaseSolution, SolutionAnnotator, SolutionResults
from ultralytics.utils.plotting import colorsclass TrackZone(BaseSolution):"""A class to manage region-based object tracking in a video stream.This class extends the BaseSolution class and provides functionality for tracking objects within a specific regiondefined by a polygonal area. Objects outside the region are excluded from tracking.Attributes:region (np.ndarray): The polygonal region for tracking, represented as a convex hull of points.line_width (int): Width of the lines used for drawing bounding boxes and region boundaries.names (List[str]): List of class names that the model can detect.boxes (List[np.ndarray]): Bounding boxes of tracked objects.track_ids (List[int]): Unique identifiers for each tracked object.clss (List[int]): Class indices of tracked objects.Methods:process: Processes each frame of the video, applying region-based tracking.extract_tracks: Extracts tracking information from the input frame.display_output: Displays the processed output.Examples:>>> tracker = TrackZone()>>> frame = cv2.imread("frame.jpg")>>> results = tracker.process(frame)>>> cv2.imshow("Tracked Frame", results.plot_im)"""def __init__(self, **kwargs):"""Initialize the TrackZone class for tracking objects within a defined region in video streams.Args:**kwargs (Any): Additional keyword arguments passed to the parent class."""super().__init__(**kwargs)default_region = [(150, 150), (1130, 150), (1130, 570), (150, 570)]self.region = cv2.convexHull(np.array(self.region or default_region, dtype=np.int32))def process(self, im0):"""Process the input frame to track objects within a defined region.This method initializes the annotator, creates a mask for the specified region, extracts tracksonly from the masked area, and updates tracking information. Objects outside the region are ignored.Args:im0 (np.ndarray): The input image or frame to be processed.Returns:(SolutionResults): Contains processed image `plot_im` and `total_tracks` (int) representing thetotal number of tracked objects within the defined region.Examples:>>> tracker = TrackZone()>>> frame = cv2.imread("path/to/image.jpg")>>> results = tracker.process(frame)"""annotator = SolutionAnnotator(im0, line_width=self.line_width)  # Initialize annotator# Create a mask for the region and extract tracks from the masked imagemask = np.zeros_like(im0[:, :, 0])mask = cv2.fillPoly(mask, [self.region], 255)masked_frame = cv2.bitwise_and(im0, im0, mask=mask)self.extract_tracks(masked_frame)# Draw the region boundarycv2.polylines(im0, [self.region], isClosed=True, color=(255, 255, 255), thickness=self.line_width * 2)# Iterate over boxes, track ids, classes indexes list and draw bounding boxesfor box, track_id, cls in zip(self.boxes, self.track_ids, self.clss):annotator.box_label(box, label=f"{self.names[cls]}:{track_id}", color=colors(track_id, True))plot_im = annotator.result()self.display_output(plot_im)  # display output with base class function# Return a SolutionResultsreturn SolutionResults(plot_im=plot_im, total_tracks=len(self.track_ids))

http://www.dtcms.com/wzjs/299388.html

相关文章:

  • 企业网站建设参考资料收录提交入口网址
  • 17173手游网站源码 手机游戏下载网站源码 带整站数据+采集培训机构是干什么的
  • 网页设计网站开发需要什么seo快速排名关键词
  • 好卡网是正规的吗哪里可以学seo课程
  • 免费 支付宝购物网站模版个人网页制作
  • 什么是公司主页简述seo和sem的区别与联系
  • app制作网站有哪些 请列举最近发生的热点新闻事件
  • 网站建设必须要具备哪些知识seo外链怎么发
  • 做网站有了域名武汉seo收费
  • WordPress板块加密企业seo整站优化方案
  • 网站如何添加浮动窗口百度竞价开户公司
  • 网站群建设规划方案网页设计制作网站教程
  • 宝安网站设计最好的公司百度链接收录提交入口
  • 成都做网站的公司哪家好如何网络推广自己的产品
  • 做追星网站效果图西安网站seo优化公司
  • 网站模板开发平台怎么做优化关键词的作用
  • wap网站建设课程要写代码吗关键词排名顾问
  • 如何用图片做网站背景优化资讯
  • 郑州建设银行官网站steam交易链接怎么改
  • wordpress音乐单独播放武安百度seo
  • 做音乐网站赚钱吗简述在线推广网站的方法
  • 网站下面 备案ip切换工具
  • php门户网站源码郑州粒米seo顾问
  • 网站搭建公司排行天津推广的平台
  • 会网站开发如何自己赚怎么做个人网页
  • 城乡建设吧部网站外贸网站制作公司哪家好
  • 物流网站建设计划书最近实时热点事件
  • 市政府网站集约化建设抖音seo推广外包公司好做吗
  • 做网站最重要的是什么北京百度快速优化排名
  • 建设时时彩网站教程百度快照入口