Drawing a rectangle around all contours in OpenCV Python

前端 未结 3 706
无人及你
无人及你 2021-02-06 15:54

i have a code which identifies contours after applying filters on video frames. Now in my case i get 3 contours and i show them by drawing rectangles around them, what i want to

3条回答
  •  庸人自扰
    2021-02-06 16:08

    Using numpy:

    boxes = []
    for c in cnts:
        (x, y, w, h) = cv2.boundingRect(c)
        boxes.append([x,y, x+w,y+h])
    
    boxes = np.asarray(boxes)
    left, top = np.min(boxes, axis=0)[:2]
    right, bottom = np.max(boxes, axis=0)[2:]
    
    cv2.rectangle(frame, (left,top), (right,bottom), (255, 0, 0), 2)
    

提交回复
热议问题