matlab - 使用 OpenCV 和 python 从图像中提取对象(指纹和签名)

标签 matlab opencv image-processing computer-vision opencv3.0

在我的网站上,我收到一张包含用户指纹和签名的图像,我不想提取这两条信息。

例如: Original Image

import os
import cv2
import numpy as np

def imshow(label, image):
    cv2.imshow(label, image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

#read image
rgb_img = cv2.imread('path')
rgb_img = cv2.resize(rgb_img, (900, 600))
gray_img = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2GRAY)

Gray Image

#canny edge detection
canny = cv2.Canny(gray_img, 50, 120)

canny edge image

# Morphology Closing
kernel = np.ones((7, 23), np.uint8)
closing = cv2.morphologyEx(canny, cv2.MORPH_CLOSE, kernel)

Morphology Closing

# Find contours 
contours, hierarchy = cv2.findContours(closing.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)

# Sort Contors by area and then remove the largest frame contour
n = len(contours) - 1
contours = sorted(contours, key=cv2.contourArea, reverse=False)[:n]

copy = rgb_img.copy()

# Iterate through contours and draw the convex hull
for c in contours:
    if cv2.contourArea(c) < 750:
        continue
    hull = cv2.convexHull(c)
    cv2.drawContours(copy, [hull], 0, (0, 255, 0), 2)
    imshow('Convex Hull', copy)    

Image divided to parts

现在我的目标是:

  1. 知道哪部分是签名,哪部分是指纹
  2. 解决轮廓重叠(如果存在)

P.S:我不确定前面的步骤是否是最终的,所以如果您有更好的步骤,请告诉我。

这些是我可能想要处理的一些困难的例子 Hard example 1 Hard example 2

最佳答案

您可以使用形态学进行指纹和签名选择。 举例来说:

import cv2 
import numpy as np
img = cv2.imread('fhZCs.png')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
img=cv2.bitwise_not(img) #negate image

#color definition
blue_upper = np.array([130,255,255])
blue_lower = np.array([115,0,0])

#blue color mask (sort of thresholding, actually segmentation)
mask = cv2.inRange(hsv, blue_lower, blue_upper)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (20,20))
finger=cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)

mask2=cv2.morphologyEx(finger, cv2.MORPH_DILATE, kernel)
signature=cv2.compare(mask2, mask, cv2.CMP_LT)
signature=cv2.morphologyEx(signature, cv2.MORPH_DILATE, kernel)

signature=cv2.bitwise_and(img, img, mask=signature)
signature=cv2.bitwise_not(signature)

finger=cv2.bitwise_and(img, img, mask=finger)
finger=cv2.bitwise_not(finger)

cv2.imwrite('finger.png', finger)
cv2.imwrite('signature.png',signature)

finger print signature

关于matlab - 使用 OpenCV 和 python 从图像中提取对象(指纹和签名),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62371903/

相关文章:

matlab - 如何获取 MATLAB 中特定目录中所有目录名称和/或所有文件的列表?

image-processing - 识别图像中的矩形区域

python - opencv检测虚线

opencv - 查找图像中边缘的密度

image-processing - 找到照片中图案/标记的位置

image - cv扩张/cv侵 eclipse : How to avoid connection between separated objects?

image - 如何在 MATLAB 中水平移动图像?

matlab - 删除包含特定范围之外的任何数字的行 - MATLAB

java - Matlab安装(LD_LIBRARY_PATH)把其他库文件弄乱了

c# - 在 Emgu Cv 中写入视频时出错