哆啦的时光机
尝试这个:该方案的基本思想是,在执行后得到图像的轮廓,threshold()并检测轮廓中最大的轮廓。import cv2image = cv2.imread("test.jpg", 1)img = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU,img)im2, contours, hier = cv2.findContours(img, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)if len(contours) != 0: #find the biggest area c = max(contours, key = cv2.contourArea) x,y,w,h = cv2.boundingRect(c) cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),1)cv2.imshow("Result", image)cv2.waitKey(0)输出: