import cv2
img = cv2.imread("./test3.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, binary = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
x, y, w, h = cv2.boundingRect(binary)#给轮廓算出一个矩形框,只是算出,并没有画,返回矩形的左上角和宽高
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2) #将boundingRect算的矩形画出来
cv2.imshow("img", img)
cv2.waitKey(0)
FR:徐海涛(hunk Xu)
QQ技术交流群:386476712