python 轮廓检测 最小外接矩形

    技术2022-07-14  65

    def shapeDetect(img): contours,hierarchy=cv2.findContours(img,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)#寻找封闭区域 cv2.drawContours(img,contours,-1,(0,0,255),3) maxCnt=-1 for i in range(len(contours)): rect = cv2.minAreaRect(contours[i]) # 最小外接矩形 box = np.int0(cv2.boxPoints(rect)) # 矩形的四个角点取整 cv2.drawContours(img, [box], 0, (255, 255, 255), 2) cv2.imshow('test.jpg',img) cv2.waitKey(0)
    Processed: 0.011, SQL: 9