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

手机网页制作网站建设丽水网站seo

手机网页制作网站建设,丽水网站seo,ps做网站logo,天津廊坊疫情最新消息导 读 本文主要介绍基于OpenCVYOLOv5实现车辆跟踪与计数的应用,并给出源码。 资源下载 基础代码和视频下载地址: https://github.com/freedomwebtech/win11vehiclecount main.py代码:​​​​​​​ import cv2import torchimport numpy as npfrom tr…

导  读

    本文主要介绍基于OpenCV+YOLOv5实现车辆跟踪与计数的应用,并给出源码。

资源下载

    基础代码和视频下载地址:

https://github.com/freedomwebtech/win11vehiclecount

图片

main.py代码:​​​​​​​

import cv2import torchimport numpy as npfrom tracker import *model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
cap=cv2.VideoCapture('highway.mp4')
count=0tracker = Tracker()def POINTS(event, x, y, flags, param):    if event == cv2.EVENT_MOUSEMOVE :          colorsBGR = [x, y]        print(colorsBGR)        
cv2.namedWindow('FRAME')cv2.setMouseCallback('FRAME', POINTS)
while True:    ret,frame=cap.read()    if not ret:        break    count += 1    if count % 3 != 0:        continue    frame=cv2.resize(frame,(1020,600))    results=model(frame)    results.pandas().xyxy[0]                       cv2.imshow("FRAME",frame)    if cv2.waitKey(0)&0xFF==27:        breakcap.release()cv2.destroyAllWindows()

tracker.py代码:​​​​​​​

import mathclass Tracker:    def __init__(self):        # Store the center positions of the objects        self.center_points = {}        # Keep the count of the IDs        # each time a new object id detected, the count will increase by one        self.id_count = 0    def update(self, objects_rect):        # Objects boxes and ids        objects_bbs_ids = []
        # Get center point of new object        for rect in objects_rect:            x, y, w, h = rect            cx = (x + x + w) // 2            cy = (y + y + h) // 2
            # Find out if that object was detected already            same_object_detected = False            for id, pt in self.center_points.items():                dist = math.hypot(cx - pt[0], cy - pt[1])
                if dist < 35:                    self.center_points[id] = (cx, cy)#                    print(self.center_points)                    objects_bbs_ids.append([x, y, w, h, id])                    same_object_detected = True                    break
            # New object is detected we assign the ID to that object            if same_object_detected is False:                self.center_points[self.id_count] = (cx, cy)                objects_bbs_ids.append([x, y, w, h, self.id_count])                self.id_count += 1
        # Clean the dictionary by center points to remove IDS not used anymore        new_center_points = {}        for obj_bb_id in objects_bbs_ids:            _, _, _, _, object_id = obj_bb_id            center = self.center_points[object_id]            new_center_points[object_id] = center
        # Update dictionary with IDs not used removed        self.center_points = new_center_points.copy()        return objects_bbs_ids

    下载测试视频highway.mp4(download.txt中有链接):

图片

    安装ultralytics:

pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple

图片

      

实现车辆检测

    添加代码查看YoloV5模型检测输出信息:

图片

图片

    添加车辆检测结果绘制:

图片

图片

      

实现车辆跟踪

    将车辆矩形坐标保存到list中:

图片

    添加对象跟踪:

图片

图片

    车辆跟踪效果:

图片

图片

      

实现车辆计数

【1】划定一个多边形区域(黄色),车辆经过此区域则计数;

cv2.polylines(frame,[np.array(areal,np.int32)],True,(0,255,255),3)

【2】绿色点标注车辆矩形框右下角坐标点,如下图:

cv2.circle(frame,(x3,y3),4,(0,255,0),-1)

图片

【3】计数原理:判断绿色点是否在黄色四边形内,如果在内计数+1

图片

图片

计算点到多边形的距离使用的是OpenCV中pointPolygonTest函数:

图片

当result > 0表示点在轮廓内,也就是车辆在多边形内。此时将车辆id编号添加到集合area_1中,然后通过len(area_1)作为车辆计数值。

注意:这里为什么不直接用count += 1来计算数量?如果用count += 1会造成很多重复计数,而代码中利用了python集合的特性,add函数添加元素时,如果元素已经存在,则不重复添加,有效的避免了重复计数问题。

最终效果如下:

图片

http://www.15wanjia.com/news/49925.html

相关文章:

  • 自己做网站哪种好做建设一个网站的具体步骤
  • 云速成美站外贸网站建设优化
  • web网站维护seo网站关键词优化价格
  • 展会网站建设佐力药业股票
  • 茌平做创建网站公司网络游戏推广
  • 广州哪里有做公司网站 什么价南宁seo全网营销
  • 做网站知名公司广告宣传网站
  • 做网站的画布是多少游戏推广话术技巧
  • 国家顶级域名网站是百度联盟是什么
  • 网站建设合作协议电子商务说白了就是干什么的
  • wordpress小工具导入厦门seo小谢
  • 一个专门做标题的网站百度云手机app下载
  • 制作网站吗百度搜索关键词设置
  • 网站制作学校运营推广是做什么的
  • 视频网站自己做服务器优化师
  • html5手机网页模板seo优化内页排名
  • 网站建设web网络软文广告
  • 正确的建议是seo快速入门教程
  • 有经验的赣州网站建设新闻热点大事件
  • 上海建站外贸seo排名赚app是真的吗
  • 网站建设电子书seo网站推广专员
  • 海外网站建设推广推广找客户平台
  • 广州 电商设计网站建设品牌运营岗位职责
  • 免费使用模板的网站成人教育培训机构十大排名
  • 河南网站建设平台如何做网站推广的策略
  • 北京到广州高铁多长时间短视频排名seo
  • 新手做网站的注意事项免费推广的方式
  • 营口网站建设公司网络服务提供者不是网络运营者
  • 手机站点青岛seo优化
  • scratch编程网站网络上哪里可以做推广