cv2.findContours()
을 사용하여 주어진 이미지의 모든 윤곽선을 찾은 다음 각 윤곽선의 경계 사각형을 찾고 모든 윤곽 rect 중에서 minX, minY, maxX, maxY를 찾으십시오. 바깥 쪽 경계선은 모든 작은 윤곽선을 포함하므로 원하는 결과를가집니다.
import cv2
import numpy as np
img = cv2.imread("/Users/anmoluppal/Downloads/mjut8.png", 0)
# Threshold and Invert the image to find the contours
ret, thresh = cv2.threshold(img, 10, 255, cv2.THRESH_BINARY_INV)
# Find the contours
im, contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
x, y, r, b = [img.shape[1]/2, img.shape[0]/2, 0, 0]
# Iterate over all the contours, and keep updating the bounding rect
for cnt in contours:
rect = cv2.boundingRect(cnt)
if rect[0] < x:
x = rect[0]
if rect[1] < y:
y = rect[1]
if rect[0] + rect[2] > r:
r = rect[0] + rect[2]
if rect[1] + rect[3] > b:
b = rect[1] + rect[3]
bounding_rect = [x, y, r-x, b-y]
# Debugging Purpose.
cv2.rectangle(img, (x, y), (r, b), np.array([0, 255, 0]), 3)

당신은'cv2.goodFeaturesToTrack을()'체크 아웃 한? –