”彩色的验证码,使用pytesseract识别出来的验证码内容一直是空“的解决办法

问题:彩色的验证码,使用pytesseract识别出来的验证码内容一直是空字符串
原因:pytesseract只识别黑色部分的内容
解决办法:先把彩色图片精确转换成黑白图片。再将黑白图片进行反相,将验证码部分的内容变成黑色,背景变成白色的。
代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2019-11-204 T11:18:38.406Z
# @Author  : HuangChang

import numpy as np
import cv2
from PIL import Image
import pytesseract

# 1、将彩色图片转换成黑白图片
##(1) read into  bgr-space
img = cv2.imread("../screenshots/verification_code.png")

##(2) convert to hsv-space, then split the channels
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)

##(3) threshold the S channel using adaptive method(`THRESH_OTSU`)
th, threshed = cv2.threshold(s, 100, 255, cv2.THRESH_OTSU | cv2.THRESH_BINARY)

##(4) print the thresh, and save the result
print("Thresh : {}".format(th))
cv2.imwrite("
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值