Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何计算特定区域中的对象数?_Python_Opencv - Fatal编程技术网

Python 如何计算特定区域中的对象数?

Python 如何计算特定区域中的对象数?,python,opencv,Python,Opencv,我正在研究车辆检测,我使用YLO检测和跟踪车辆现在我想计算特定区域内检测到的车辆数量,我画了一个矩形,我想在其中计数: cv2.rectangle(image, point, (point[0] + 200, point[1] + 120), (0, 0, 255), 0) 检测到的车辆被矩形包围。 以一种简单的方式,我想计算一个大矩形中包含的矩形的数量我只计算检测矩形和我想计算数量的矩形的交点 from collections import namedtuple Re

我正在研究车辆检测,我使用YLO检测和跟踪车辆现在我想计算特定区域内检测到的车辆数量,我画了一个矩形,我想在其中计数:

    cv2.rectangle(image, point, (point[0] + 200, point[1] + 120), (0, 0, 255), 0)
检测到的车辆被矩形包围。
以一种简单的方式,我想计算一个大矩形中包含的矩形的数量

我只计算检测矩形和我想计算数量的矩形的交点

    from collections import namedtuple
    Rectangle = namedtuple('Rectangle', 'xmin ymin xmax ymax')  
    def intersection(a, b):  # a and b are the 2 rectangle
    dx = min(a.xmax, b.xmax) - max(a.xmin, b.xmin)
    dy = min(a.ymax, b.ymax) - max(a.ymin, b.ymin)
    if (dx>=0) and (dy>=0):
       return dx*dy

如果结果为>0,则表示两个矩形之间存在交点。

上有关于此的教程,您只需迭代所有小矩形,并仅计算左上点>=大矩形左上点和右下点的矩形