img = cv2.imread('/home/kvnp/Desktop/v02J6.jpg',0) #read in the image with correct dtype
_,thresh = cv2.threshold(img,200,255,0) # threshold the image
_,contours,_ = cv2.findContours(thresh, 1, 2) # find the contours
cnt = sorted(contours, key = lambda c: -len(c))[0] # order from largest to smallest and select the largest
x,y,w,h = cv2.boundingRect(cnt) # make bounding rectangle around the largest contour
corners = np.array([[x,y],[x+w,y],[x+w,y+h],[x,y+h]]) # make array of corners sorted clockwise
只要得到轮廓,然后找到边界矩形。检查官方文件中的this tutorial。在
矩形左上、右下点坐标((x1,y1),(x2,y2)):
^{pr2}$结果:
只要调整cv2 tutorial,就可以找到最大的轮廓,然后得到它的边界矩形。在
我看到的这个图像
^{pr2}$相关问题 更多 >
编程相关推荐