最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python基于opencv批量生成驗(yàn)證碼的示例

 更新時(shí)間:2021年04月28日 11:43:04   作者:奈何緣淺wyj  
這篇文章主要介紹了python基于opencv批量生成驗(yàn)證碼的示例,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下

基本思路是使用opencv來把隨機(jī)生成的字符,和隨機(jī)生成的線段,放到一個(gè)隨機(jī)生成的圖像中去。

  雖然沒有加復(fù)雜的形態(tài)學(xué)處理,但是目前看起來效果還不錯(cuò)

  嘗試生成1000張圖片,但是最后只有998張,因?yàn)橛杏兄貜?fù)的,被覆蓋掉了。

  代碼如下:

import cv2
import numpy as np
line_num = 10
pic_num = 1000
path = "./imgs/"
def randcolor():        
    return (np.random.randint(0,255),np.random.randint(0,255),np.random.randint(0,255))
    
def randchar():
    return chr(np.random.randint(65,90))
    
def randpos(x_start,x_end,y_start,y_end):
    return (np.random.randint(x_start,x_end),
            np.random.randint(y_start,y_end))
    
    
img_heigth = 60
img_width = 240
for i in range(pic_num):
    img_name = ""
    #生成一個(gè)隨機(jī)矩陣,randint(low[, high, size, dtype])
    img = np.random.randint(100,200,(img_heigth,img_width, 3), np.uint8)
    #顯示圖像
    #cv2.imshow("ranImg",img)
    
    x_pos = 0
    y_pos = 25
    for i in range(4):
        char = randchar()
        img_name += char
        cv2.putText(img,char,
                    (np.random.randint(x_pos,x_pos + 50),np.random.randint(y_pos,y_pos + 35)), 
                    cv2.FONT_HERSHEY_SIMPLEX,
                    1.5,
                    randcolor(),
                    2,
                    cv2.LINE_AA)
        x_pos += 45
    
    #cv2.imshow("res",img)
    
    #添加線段
    for i in range(line_num):
        img = cv2.line(img,
                       randpos(0,img_width,0,img_heigth),
                       randpos(0,img_width,0,img_heigth),
                        randcolor(),
                        np.random.randint(1,2))
        
    #cv2.imshow("line",img)
    cv2.imwrite(path + img_name + ".jpg",img)
    #cv2.waitKey(0)                  
    #cv2.destroyAllWindows()

  結(jié)果:

以上就是python基于opencv批量生成驗(yàn)證碼的示例的詳細(xì)內(nèi)容,更多關(guān)于python 批量生成驗(yàn)證碼的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

长武县| 蕉岭县| 广元市| 合川市| 南康市| 沐川县| 读书| 筠连县| 新余市| 贵州省| 随州市| 沙雅县| 禹城市| 科技| 塘沽区| 绩溪县| 抚州市| 罗田县| 竹溪县| 璧山县| 江永县| 原阳县| 太仓市| 大丰市| 左权县| 青龙| 斗六市| 日照市| 云南省| 漯河市| 木兰县| 青岛市| 吉首市| 依安县| 边坝县| 会昌县| 邮箱| 左权县| 仁布县| 潜山县| 剑河县|