RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 970467
Accepted
Егор Никоноров
Егор Никоноров
Asked:2020-04-17 00:48:22 +0000 UTC2020-04-17 00:48:22 +0000 UTC 2020-04-17 00:48:22 +0000 UTC

如何在数组中显示所选对象的极值点坐标?

  • 772

物体识别有一段代码:

from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path , "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(
    input_file_path = os.path.join(execution_path, "Car - 2165.mp4"),
    output_file_path = os.path.join(execution_path, "traffic_detected"),
    frames_per_second = 20,
    log_progress = True
)

assert isinstance(video_path, object)
print(video_path)   

如何在数组(具体来说,矩形等)中显示所选对象的极值点坐标?

python
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    MaxU - stop genocide of UA
    2020-04-17T19:21:56Z2020-04-17T19:21:56Z

    detector.detectObjectsFromVideo()函数可以作为参数传递给函数per_frame_function。处理完每一帧后,将调用传递的函数。此函数在调用时将传递以下参数:

    • frame_number- 帧的序列号
    • output_array- 在帧中检测到的对象数组,由以下形式的字典组成:

      {'box_points': (362, 295, 443, 355), 'name': 'boat', 'percentage_probability': 26.67}
      
    • output_count- 统计:每个类的对象数。例子:

      {'bus': 4, 'boat': 3, 'person': 1, 'car': 8}
      

    为了一起收集这些数据,我会使用Pandas模块:

    import pandas as pd
    
    data = []
    
    def collect_detected_objs(*args):
        data.append(args)
    
    ret = detector.detectObjectsFromVideo(
        input_file_path = video_fn,
        output_file_path = os.path.join(execution_path, "traffic_detected"),
        frames_per_second = 20,
        log_progress = True,
        per_frame_function=collect_detected_objs
    )
    
    d = pd.concat([pd.DataFrame(x[1]).assign(frame=x[0]) for x in data])
    stats = pd.DataFrame([x[2] for x in data], index=[x[0] for x in data])
    

    结果:

    In [233]: d
    Out[233]:
                     box_points    name  percentage_probability  frame
    0       (504, 53, 590, 163)   truck               50.516695      1
    1   (1008, 850, 1222, 1077)   truck               52.645624      1
    2      (768, 124, 868, 261)   truck               75.007182      1
    3      (534, 164, 600, 233)     car               63.670057      1
    4   (1008, 850, 1222, 1077)     car               64.012623      1
    5      (625, 121, 692, 239)     car               68.127060      1
    6        (584, 24, 633, 87)     car               83.921510      1
    7      (638, 413, 661, 472)  person               53.726447      1
    8      (445, 722, 475, 789)  person               58.984256      1
    9      (481, 673, 507, 719)  person               61.079180      1
    ..                      ...     ...                     ...    ...
    8      (423, 873, 452, 936)  person               58.492571     47
    0      (768, 125, 868, 261)   truck               68.915749     48
    1      (537, 183, 597, 244)     car               78.283107     48
    2   (1010, 850, 1223, 1079)     car               78.731704     48
    3        (577, 13, 627, 72)     car               85.132539     48
    4      (620, 156, 694, 203)     car               90.549046     48
    5      (860, 458, 886, 521)  person               50.013673     48
    6      (423, 873, 450, 936)  person               53.440607     48
    7      (397, 745, 424, 809)  person               57.603621     48
    8      (628, 396, 650, 447)  person               59.033847     48
    
    [549 rows x 4 columns]
    
    In [234]: stats
    Out[234]:
        car  person  truck
    1     4       5      3
    2     4       5      3
    3     4       6      3
    4     4       6      2
    5     4       6      3
    6     4       6      4
    7     4       6      3
    8     4       7      3
    9     4       7      3
    10    4       7      3
    ..  ...     ...    ...
    39    5       4      2
    40    5       4      2
    41    5       5      1
    42    5       1      1
    43    5       2      1
    44    4       2      1
    45    4       2      1
    46    4       3      1
    47    4       4      1
    48    4       4      1
    
    [48 rows x 3 columns]
    

    整个代码:

    import os
    import cv2
    from imageai.Detection import ObjectDetection, VideoObjectDetection
    import pandas as pd
    
    execution_path = os.getcwd()
    
    yolo_model_fn = r'C:\work\ML\.data\misc\yolo.h5'
    video_fn = r'C:\download\cut2.mp4'
    
    detector = VideoObjectDetection()
    detector.setModelTypeAsYOLOv3()
    detector.setModelPath(yolo_model_fn)
    detector.loadModel()
    
    data = []
    
    def collect_detected_objs(*args):
        data.append(args)
        #detected.append(pd.DataFrame(detections).assign(frame=frame_pos))
        #stats.append(pd.Series(obj_stats, index=[frame_pos]))
    
    ret = detector.detectObjectsFromVideo(
        input_file_path = video_fn,
        output_file_path = os.path.join(execution_path, "traffic_detected"),
        frames_per_second = 20,
        log_progress = True,
        per_frame_function=collect_detected_objs
    )
    
    d = pd.concat([pd.DataFrame(x[1]).assign(frame=x[0]) for x in data])
    stats = pd.DataFrame([x[2] for x in data], index=[x[0] for x in data])
    
    print(d)
    print(stats)

    • 2

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    根据浏览器窗口的大小调整背景图案的大小

    • 2 个回答
  • Marko Smith

    理解for循环的执行逻辑

    • 1 个回答
  • Marko Smith

    复制动态数组时出错(C++)

    • 1 个回答
  • Marko Smith

    Or and If,elif,else 构造[重复]

    • 1 个回答
  • Marko Smith

    如何构建支持 x64 的 APK

    • 1 个回答
  • Marko Smith

    如何使按钮的输入宽度?

    • 2 个回答
  • Marko Smith

    如何显示对象变量的名称?

    • 3 个回答
  • Marko Smith

    如何循环一个函数?

    • 1 个回答
  • Marko Smith

    LOWORD 宏有什么作用?

    • 2 个回答
  • Marko Smith

    从字符串的开头删除直到并包括一个字符

    • 2 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5