Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.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
OpenCV Python-cv2.groupRectangles()返回空元组_Python_Opencv - Fatal编程技术网

OpenCV Python-cv2.groupRectangles()返回空元组

OpenCV Python-cv2.groupRectangles()返回空元组,python,opencv,Python,Opencv,我在2D技术图纸中围绕数字绘制矩形。我正在使用cv2.findContours()查找数字。我正在尝试使用cv2.groupRectangles()对重叠的矩形进行分组,但当我尝试打印矩形列表时,它正在打印() all_rects是我使用轮廓函数找到的所有矩形的列表,格式为[x,y,w,h] one_rect = [] all_rects = [] for cnt in contours: x,y,w,h = cv2.boundingRect(cnt) one_rect = [x

我在2D技术图纸中围绕数字绘制矩形。我正在使用
cv2.findContours()
查找数字。我正在尝试使用
cv2.groupRectangles()
对重叠的矩形进行分组,但当我尝试打印
矩形列表时,它正在打印()

all_rects
是我使用轮廓函数找到的所有矩形的列表,格式为[x,y,w,h]

one_rect = []
all_rects = []
for cnt in contours:
    x,y,w,h = cv2.boundingRect(cnt)
    one_rect = [x,y,w,h]
    area = cv2.contourArea(cnt) 
    if area < 1000: #if rectangle is very large
        all_rects.append(one_rect)
    else:
        print("area too big")

print(all_rects)


rectList,weights=cv2.groupRectangles(all_rects, 1, 0.2)
print(rectList)
for (mx,my,mw,mh) in rectList:
    cv2.rectangle(img, (mx,my), (mx+mw, my+mh), (0,0,0), 5)
    cv2.imshow("grouped", img)
    cv2.waitKey(0)
one_rect=[]
所有矩形=[]
对于轮廓中的cnt:
x、 y,w,h=cv2.boundingRect(cnt)
one_rect=[x,y,w,h]
面积=cv2。轮廓面积(cnt)
如果面积<1000:#如果矩形非常大
所有元素。追加(一个元素)
其他:
打印(“区域太大”)
打印(全部)
矩形列表,权重=cv2。组矩形(所有矩形,1,0.2)
打印(列表)
对于矩形列表中的(mx、my、mw、mh):
cv2.矩形(img,(mx,my),(mx+mw,my+mh),(0,0,0),5)
cv2.imshow(“分组”,img)
cv2.等待键(0)

我希望它返回x、y、w、h点列表,但是
print(rectList)
正在返回“()”

或者
cv2。groupRectangles
没有返回
None
或者
print(rectList)
没有打印
)。你能告诉我们在
weights
中有什么吗?如果你打印它,weights会给我们什么?``print(weights)也在打印()显示
print(all rects)
的输出
cv2。groupRectangles
不会返回
None
或者
print(rectList)
不会打印
()
。你能给我们看一下重量中有什么吗?如果你打印它,重量会给我们什么?``打印(重量)也在打印()给我们看打印(全部)的输出。