• 【深度学习】Yolov8 区域计数


    git:https://github.com/ultralytics/ultralytics/blob/main/examples/YOLOv8-Region-Counter/readme.md
    很长时间没有做yolov的项目了,最近一看yolov8有一个区域计数的功能,不得不说很实用啊。
    b站:https://www.bilibili.com/video/BV1Ng4y1d7Yr/?spm_id_from=333.999.0.0

    1. 开干

    照着 git整就行;
    pipe install ultralytics
    1.安装库

    # Clone ultralytics repo
    git clone https://github.com/ultralytics/ultralytics
    
    # cd to local directory
    cd ultralytics/examples/YOLOv8-Region-Counter
    
    • 1
    • 2
    • 3
    • 4
    • 5
    1. Run the Region Counting Using Ultralytics Yolov8
    # If you want to save results
    python yolov8_region_counter.py --source "path/to/video.mp4" --save-img --view-img
    
    # If you want to run model on CPU
    python yolov8_region_counter.py --source "path/to/video.mp4" --save-img --view-img --device cpu
    
    # If you want to change model file
    python yolov8_region_counter.py --source "path/to/video.mp4" --save-img --weights "path/to/model.pt"
    
    # If you dont want to save results
    python yolov8_region_counter.py --source "path/to/video.mp4" --view-img
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    Usage Options

    --source: Specifies the path to the video file you want to run inference on.
    --device: Specifies the device cpu or 0
    --save-img: Flag to save the detection results as images.
    --weights: Specifies a different YOLOv8 model file (e.g., yolov8n.pt, yolov8s.pt, yolov8m.pt, yolov8l.pt, yolov8x.pt).
    --line-thickness: Specifies the bounding box thickness
    --region-thickness: Specifies the region boxes thickness
    --track-thickness: Specifies the track line thickness
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    counting_regions = [
        {
            "name": "YOLOv8 Polygon Region",
            "polygon": Polygon(
                [(50, 80), (250, 20), (450, 80), (400, 350), (100, 350)]
            ),  # Polygon with five points (Pentagon)
            "counts": 0,
            "dragging": False,
            "region_color": (255, 42, 4),  # BGR Value
            "text_color": (255, 255, 255),  # Region Text Color
        },
        {
            "name": "YOLOv8 Rectangle Region",
            "polygon": Polygon(
                [(200, 250), (440, 250), (440, 550), (200, 550)]
            ),  # Rectangle with four points
            "counts": 0,
            "dragging": False,
            "region_color": (37, 255, 225),  # BGR Value
            "text_color": (0, 0, 0),  # Region Text Color
        },
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    1. 业务化改造,因为原仓库代码有问题
    2. python yolov8_region_counter.py --weights yolov8n.pt --device 0 --source D:\code\python_project\ultralytics\examples\YOLOv8-Region-Counter\test_person.mp4 --view-img --track-thickness 5
      –track-thickness参数 就是那几根线,我不清楚这几根线有啥意思。
      代码运行:

    问题:1 有追踪的线
    在这里插入图片描述
    把线去掉
    屏蔽这行代码,156行

    cv2.polylines(frame, [points], isClosed=False, color=bbox_color, thickness=track_thickness)
    
    • 1

    在这里插入图片描述
    问题2:生成的结果mp4 无法播放
    不是bug,是我的运行命令没用对。
    python yolov8_region_counter.py --weights yolov8n.pt --device 0 --source test_person.mp
    4 --view-img --save-img

    改进

    可以自定义框的位置,
    在这里插入图片描述

    所使用命令:

    python yolov8_region_counter.py --weights yolov8n.pt --device 0 --source test_person.mp
    4 --view-img --save-img

  • 相关阅读:
    HTML小游戏9 —— 潜行游戏《侠盗罗宾汉》(附完整源码)
    LeetCode220801_65、寻找两个正序数组的中位数
    《深入理解java虚拟机》第七章读书笔记——虚拟机类加载机制
    react:函数组件
    【光学】Matlab实现色散曲线拟合
    28.在springboot中使用thymeleaf的内置对象(#request,#session,session)
    hive 分隔符
    【子串】151. 反转字符串中的单词【中等】
    这世上又多了一只爬虫(spiderflow)
    Nginx之memcached_module模块解读
  • 原文地址:https://blog.csdn.net/weixin_40293999/article/details/134222589