当前位置:网站首页>Gif verification code analysis
Gif verification code analysis
2022-06-23 07:46:00 【Archaeologist LX (Li Xi)】
GIF Verification Code and Common captcha The difference is that the words on the picture are hidden and visible from time to time , If you view by frame , Every frame is missing text .
GIF Example of verification code picture :

So now we have the following ideas :
- Scheme 1 : Take several screenshots of the picture , Then the array of all pictures is merged and overwritten in one picture , Then we can recognize the complete picture .
- Option two : Frame the picture multiple times , Then identify each picture individually , The highest frequency of characters in each position is the correct result .
Scheme I code :
from PIL import Image
import numpy as np
import cv2
path = r"C:\Users\lixi\Desktop\p1.gif"
image =Image.open(path)
shapes = []
for i in range(1,4):
image.seek(i)
image.save(f'image/{
i}.png')
shapes.append(np.array(image))
result = np.subtract(shapes[0], shapes[2])
result2 = np.subtract(shapes[0], shapes[1])
result3 = np.subtract(shapes[1], shapes[2])
cv2.imwrite("image/result.png", shapes[0] + result+result2+result3)
The merged image :
Scheme II code :( Code transferred from https://juejin.cn/post/6855483334512869389)
# -*- coding: utf-8 -*-
# @Software: PyCharm
import requests
import time
import json
from PIL import Image
from io import BytesIO
from collections import Counter
def get_max_char(str):
''' Get the most frequent character :param str: :return: '''
count = Counter(str)
count_list = list(count.values())
max_value = max(count_list)
max_list = []
for k, v in count.items():
if v == max_value:
max_list.append(k)
return max_list[0]
def recogition(yzm_data):
''' Verification code recognition :param yzm_data: :return: '''
resp = requests.post('http://127.0.0.1:8080', data=yzm_data)
return resp.text
def img_to_text(yzmdatas):
''' Picture to character :param length: :return: '''
yzm1 = ""
yzm2 = ""
yzm3 = ""
yzm4 = ""
for data in yzmdatas:
text = recogition(data)
json_obj = json.loads(text)
yzm_text = json_obj.get("code","")
# The length of the verification code in this paper is 4 In the actual test, as long as the length is greater than or equal to 4 All of them can be counted , It does not affect the recognition accuracy
if len(yzm_text) == 4:
l_yzm = list(yzm_text)
yzm1 = yzm1 + l_yzm[0]
yzm2 = yzm2 + l_yzm[1]
yzm3 = yzm3 + l_yzm[2]
yzm4 = yzm4 + l_yzm[3]
yzm1 = get_max_char(yzm1)
yzm2 = get_max_char(yzm2)
yzm3 = get_max_char(yzm3)
yzm4 = get_max_char(yzm4)
return yzm1+yzm2+yzm3+yzm4
def download():
''' Download verification code :return: '''
# Verification code address
url = 'http://credit.customs.gov.cn/ccppserver/verifyCode/creator'
resp = requests.get(url)
data = resp.content
return data
def gif_to_png(length,image):
''' gif Frame extraction :param length: :param image: :return: '''
try:
yzm_list = []
for i in range(1, length):
image.seek(i)
stream = BytesIO()
image.save(stream, 'PNG')
s = stream.getvalue()
yzm_list.append(s)
return yzm_list
except Exception as e:
print(e)
return None
def handle_yzm(length):
''' Process verification code :return: '''
gif = download()
start = time.time()
if gif:
data = BytesIO(gif)
image = Image.open(data)
png_list = gif_to_png(length, image)
if png_list:
yzm_text = img_to_text(png_list)
with open("./Gif_IMG/{}_{}.gif".format(yzm_text, str(time.time())),"wb") as fw:
fw.write(gif)
end = time.time()
print(" Frame extraction length:{}- Spend time :{}".format(length, end - start))
def run():
# Frame extraction length : The specific number of frames can be based on the actual gif Recognition accuracy to adjust .
# The less frames are extracted, the lower the recognition rate may be , But the time required for identification will be reduced .23 Frame accuracy 98%, Time 1s; 6 Frame accuracy 85%, Time 0.5s about
# Find a balance between recognition speed and accuracy
length = 10
# Number of recognized pictures
num = 20
for i in range(num):
handle_yzm(length)
if __name__ == '__main__':
run()
Scheme 1 is simple and crude , But it will also combine other interference elements , Therefore, other processing methods are required after the merger .
Scheme 2 code transfer to others , The effect will be better , First identify and then synthesize , But it's not efficient , You need to change it yourself .
The code of both schemes needs to be optimized and adjusted when used , We choose the corresponding scheme according to our own needs .
边栏推荐
- 在kubernetes中部署kubersphere
- 数学知识:欧拉函数—欧拉函数
- 【PyQt5系列】修改计数器实现控制
- vs在连接SQL时出现的问题myconn.OPen();无法运行
- 【云计算赛项】职业技能竞赛--容器开发部分例题Pig快速开发框架
- leetcode210. Schedule II 207 Curriculum topology sorting DFS BFS
- Solutions to abnormal network connection of Xiaoai speakers
- 【唠嗑篇】普通人到底该怎么学技术啊?
- Pseudocode specification, pseudocode online editor,
- Feelm joined the Carbon Disclosure Project as an initiative of Smallville to deal with climate change emergencies
猜你喜欢

Abnormal logic reasoning problem of Huawei software test written test

GIF验证码分析

3DMAX plug-in development environment configuration and fileexport and utilities template testing

Wechat multiplayer chat and Roulette Games (websocket Implementation)

这道字符串反转的题目,你能想到更好的方法吗?

浅谈ThreadLocal和InheritableThreadLocal,源码解析

传智教育 | 项目发布前如何打tag标签及标签命名规范
![[pyqt5 series] modify the counter to realize control](/img/de/c997a19ad72619b0fd2fcd0124ee1a.png)
[pyqt5 series] modify the counter to realize control

What is customer experience automation?

HCIP之路
随机推荐
MySQL (11) - sorting out MySQL interview questions
Qt 使用QDomDocument读取xml文件
Wechat multiplayer chat and Roulette Games (websocket Implementation)
论文写作之WPS安装Mathtype插件编写数学公式
How MySQL converts a date to a number
Qt工程报错:-1: error: Cannot run compiler ‘clang++‘. Output:mingw32-make.exe
数学知识:欧拉函数—欧拉函数
Realization of rolling broadcast effect
MySQL (IV) - MySQL storage engine
SimpleDateFormat 线程安全问题
MySQL transaction isolation level
RTMP streaming exception fast recovery scheme
Friends of the week
three. Solution to stripe shadow and grid shadow in JS
Unity图片加载和保存
测试apk-异常管控NetTraffic攻击者开发
Left multiply right multiply matrix problem
Talk about routing design in service governance
openni.utils.OpenNIError: (OniStatus.ONI_STATUS_ERROR, b‘DeviceOpen using default: no devices found‘
Online JSON to CSharp (c) class tool