OpenCV-印章提取

思路:将原始图像转为HSV 格式,再通过颜色分割进行提取

import cv2
import numpy as np
np.set_printoptions(threshold=np.inf)
image = cv2.imread('C:\\Users\\user\\Desktop\\1093303-20171008194557012-1266465844.png')
hue_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
low_range = np.array([150, 103, 100])
high_range = np.array([180, 255, 255])
th = cv2.inRange(hue_image, low_range, high_range)
index1 = th == 255

img = np.zeros(image.shape, np.uint8)
img[:, :] = (255,255,255)
img[index1] = image[index1]#(0,0,255)
cv2.imshow('img', img)

原始图片

OpenCV-印章提取_第1张图片

提取的印章

OpenCV-印章提取_第2张图片

你可能感兴趣的:(OpenCV,python)