使用python3怎么切割验证码图片

  介绍

这期内容当中小编将会给大家带来有关使用python3怎么切割验证码图片,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

python是什么意思

python是一种跨平台的,具有解释性,编译性,互动性和面向对象的脚本语言,其最初的设计是用于编写自动化脚本,随着版本的不断更新和新功能的添加,常用于用于开发独立的项目和大型项目。

<>强切割前图片

使用python3怎么切割验证码图片

<>强切割后四个图片

使用python3怎么切割验证码图片

<强>代码

#编码:use utf8   import 操作系统   得到PIL  import 形象,ImageDraw ImageFile   import  numpy   import  pytesseract   import  cv2   import  imagehash   import 集合   class  pictureIdenti:      ,# rownum:切割行数;colnum:切割列数;dstpath:图片文件路径;img_name:要切割的图片文件   ,def  splitimage(自我,,rownum=1, colnum=4, dstpath=癉: \ \ python36_crawl \ Veriycode"工作,,   ,,,,img_name=癉: \ \ python36_crawl \ Veriycode \ mode_5246.png"工作,):   时间=img 才能;Image.open (img_name)   ,,w, h =img.size   if 才能rownum  & lt;=, h 以及colnum  & lt;=, w:   ,才能打印(& # 39;Original  image 信息:,% sx % s,, % s,, % & # 39;, %, (h, w,还以为,img.format, img.mode))   ,才能打印(& # 39;开始处理图片切割,,请稍候…& # 39;)      ,,s =, os.path.split (img_name)   ,,if  dstpath ==, & # 39; & # 39;:   ,,,dstpath  s [0]=,   ,,fn =, s [1] .split(& # 39; # 39;公司)   ,,basename =, fn [0]   ,,ext =, fn [1]      ,,num =1   ,,rowheight =, h //rownum   ,,colwidth =, w //colnum   ,,file_list =, []   ,,for  r 拷贝范围(rownum):   ,,,index =0   ,,,for  c 拷贝范围(colnum):   ,,,,#,(左,上,右,,,低)   ,,,,#,box =, (c  *, colwidth,, r  *, rowheight,,(时间+ c  1), *, colwidth,,(时间+ r  1), *, rowheight)   ,,,,if  index<1:   ,,,,,colwid =colwidth + 6   ,,,,elif  index<2:   ,,,,,colwid =, colwidth  + 1   ,,,,elif  index  & lt;, 3:   ,,,,,colwid =colwidth      ,,,,box =, (c  *, colwid,, r  *, rowheight,,(时间+ c  1), *, colwid,,(时间+ r  1), *, rowheight)   ,,,,newfile =, os.path.join (dstpath, basename  +, & # 39; _ # 39;, +, str (num), +, & # 39;强生# 39;,+,ext)   ,,,,file_list.append (newfile中)   ,,,,img.crop(箱).save (os.path.join (dstpath, basename  +, & # 39; _ # 39;, +, str (num), +, & # 39;强生# 39;,+,ext),, ext)   ,,,,num =, num  + 1   ,,,,指数+=1   ,,for  f  file_list:拷贝   ,,,印刷(f)   ,才能打印(& # 39;图片切割完毕,共生成,% s 张小图片# 39;公司,%,num)

上述就是小编为大家分享的使用python3怎么切割验证码图片了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。

使用python3怎么切割验证码图片