我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用cv2.MORPH_GRADIENT。
def recognize_text(original): idcard = original gray = cv2.cvtColor(idcard, cv2.COLOR_BGR2GRAY) # Morphological gradient: kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5)) opening = cv2.morphologyEx(gray, cv2.MORPH_GRADIENT, kernel) # Binarization ret, binarization = cv2.threshold(opening, 0.0, 255.0, cv2.THRESH_BINARY | cv2.THRESH_OTSU) # Connected horizontally oriented regions kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (9, 1)) connected = cv2.morphologyEx(binarization, cv2.MORPH_CLOSE, kernel) # find countours _, contours, hierarchy = cv2.findContours( connected, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE ) return contours, hierarchy