如何从图像中提取签名(Python脚本)? [英] How to extract signature from an image (python script)?
本文介绍了如何从图像中提取签名(Python脚本)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是签名的示例图片:
如何从没有背景的图像中获取签名,以便将其粘贴到用户图像上.如果背景不是白色怎么办?
我尝试了
但是它的边缘不是很干净!外面有人可以排序吗?
Here is a sample image of signature :
How to get the signature from this image without background so that I can paste it over user image. What if background is not white?
I have tried this, how to customize it for different background colors?
解决方案
Just started with Python myself but thought I'd have a go at a solution - came up with this:
#!/usr/bin/python2
import cv2
import numpy as np
file_name = "/tmp/signature.jpg" # your signature image...
image = cv2.imread(file_name, 1)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGBA)
# note: [R,G,B,255] below, so first 3 numbers [255,255,255] are your white
# background pixels to be converted to RGBA setting of [0,0,0,0] (transparent)
image[np.all(image == [255, 255, 255, 255], axis=2)] = [0, 0, 0, 0]
cv2.imwrite("/tmp/signature-transparent.png", image)
This script will grab your signature.jpg, make a transparent background from all the white pixels it finds, then write it to signature.png.
Looks like this:
However it's not exactly clean around the edges! Anyone out there who can sort that?
这篇关于如何从图像中提取签名(Python脚本)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文