Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.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
C++ 高效分组重叠矩形_C++_Python_Algorithm_Boost_Computer Vision - Fatal编程技术网

C++ 高效分组重叠矩形

C++ 高效分组重叠矩形,c++,python,algorithm,boost,computer-vision,C++,Python,Algorithm,Boost,Computer Vision,将重叠矩形分组的最佳方法?我尝试过使用OpenCV,但grouprectangles方法并没有达到预期效果 我考虑过这样做: L = [every rectangle] L_next = [] while not L.empty(): for rectangle in L: L.remove(rectangle) for other_rectangle in L: if rectangle overlaps with other_r

将重叠矩形分组的最佳方法?我尝试过使用OpenCV,但grouprectangles方法并没有达到预期效果

我考虑过这样做:

L = [every rectangle]
L_next = []
while not L.empty():
    for rectangle in L:
        L.remove(rectangle)
        for other_rectangle in L:
            if rectangle overlaps with other_rectangle:
                L_next += rectangle + other_rectangle
    L = L_next
    L_next = []
由于每个未合并的矩形都将从下一个列表中删除,因此在最坏的情况下,我将对外部循环进行n/2次迭代。这两个内部循环应该执行n次和n-1次,这样在最坏的情况下,算法应该大致在^3上,假设我没有遗漏任何东西,并且每个步骤只需要O1

问题:

我需要使用等价类或某种程度的东西来正确合并矩形组。Boost有类似的产品吗

2这似乎是一种必须经常进行的操作,所以我很惊讶没有找到更多的资料。怎么回事

3假设真的没有什么东西可以实现这一点,有人有什么建议来改进我的方法吗

4查看两个矩形是否重叠的最佳方法是什么?

我想看看解决问题的方法。由于矩形重叠检测在游戏中非常常见,我想它们的实现在计算复杂度方面相当不错