2016-06-16 3 views
0

연구 후, 나는 이와 비슷한 몇 가지 질문을 보았습니다 : OpenCV groupRectangles - getting grouped and ungrouped rectangles (대부분은 C++입니다). 그러나 그 중 단 한 건도 없습니다. 중첩 사각형을 하나의 단일 사각형으로 결합하고 싶습니다. Image오버랩 사각형 (파이썬) 합치기

내 진행 : 만 대신 groupRectangle 내가 싶었지만 아무것도하지 않았다 무엇을 할 것이라고 기대되었다 내 code.I의 조각을 게시

for cnt in large_contours: 
    x,y,w,h = cv2.boundingRect(cnt) 
    mec=x,y,w,h 
    rectVec=cv2.rectangle(img_and_contours,(x,y),(x+w,y+h),(0,255,0),2) 
    #cv2.rectangle(img_and_contours, cv2.boundingRect(large_contours[cnt]),(0,255,0)); 
    rectList, weights = cv2.groupRectangles(mec, 3,0.2) 

이 나에게 오류를 제공

rectList,weights = cv2.groupRectangles(mec,3,0.2) TypeError: rectList Blockquote

답변

0

**Non max suppression**이라는 알고리즘이 있습니다. 이 함수는 사각형 배열을 입력으로 가져와 최대 사각형을 출력합니다. 여기 코드는 다음과 같습니다

def non_max_suppression_fast(boxes, overlapThresh): 
    # if there are no boxes, return an empty list 
    if len(boxes) == 0: 
     return [] 

    # if the bounding boxes integers, convert them to floats -- 
    # this is important since we'll be doing a bunch of divisions 
    if boxes.dtype.kind == "i": 
     boxes = boxes.astype("float") 
# 
    # initialize the list of picked indexes 
    pick = [] 

    # grab the coordinates of the bounding boxes 
    x1 = boxes[:,0] 
    y1 = boxes[:,1] 
    x2 = boxes[:,2] 
    y2 = boxes[:,3] 

    # compute the area of the bounding boxes and sort the bounding 
    # boxes by the bottom-right y-coordinate of the bounding box 
    area = (x2 - x1 + 1) * (y2 - y1 + 1) 
    idxs = np.argsort(y2) 

    # keep looping while some indexes still remain in the indexes 
    # list 
    while len(idxs) > 0: 
     # grab the last index in the indexes list and add the 
     # index value to the list of picked indexes 
     last = len(idxs) - 1 
     i = idxs[last] 
     pick.append(i) 

     # find the largest (x, y) coordinates for the start of 
     # the bounding box and the smallest (x, y) coordinates 
     # for the end of the bounding box 
     xx1 = np.maximum(x1[i], x1[idxs[:last]]) 
     yy1 = np.maximum(y1[i], y1[idxs[:last]]) 
     xx2 = np.minimum(x2[i], x2[idxs[:last]]) 
     yy2 = np.minimum(y2[i], y2[idxs[:last]]) 

     # compute the width and height of the bounding box 
     w = np.maximum(0, xx2 - xx1 + 1) 
     h = np.maximum(0, yy2 - yy1 + 1) 

     # compute the ratio of overlap 
     overlap = (w * h)/area[idxs[:last]] 

     # delete all indexes from the index list that have 
     idxs = np.delete(idxs, np.concatenate(([last], 
     np.where(overlap > overlapThresh)[0]))) 

    # return only the bounding boxes that were picked using the 
    # integer data type 
    return boxes[pick].astype("int") 

가 당신을 도울 수 있기를 바랍니다.

+0

귀하의 의견에 감사드립니다. [351, 544, 9, 5], [514, 540, 8, 6], [467, 539, 8, 7], [409, 538, 13, 11], [201 , 538, 17, 8], [64, 538, 15, 11], [314, 537, 23, 10], [398, 534, 3, 9] .... 256 좌표] non_max_suppression_fast 함수? – skyrocket

+0

@skyrocket 목록으로 변환 – VICTOR

+0

내가 가져 오는 TypeError : non_max_suppression_fast()는 2 개의 위치 지정 인수를 사용하지만 3은 –