国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python基于opencv批量生成驗證碼的示例

瀏覽:13日期:2022-06-20 18:04:58

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

雖然沒有加復雜的形態學處理,但是目前看起來效果還不錯

嘗試生成1000張圖片,但是最后只有998張,因為有有重復的,被覆蓋掉了。

代碼如下:

import cv2import numpy as npline_num = 10pic_num = 1000path = './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 = 60img_width = 240for i in range(pic_num): img_name = '' #生成一個隨機矩陣,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 += charcv2.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()

結果:

python基于opencv批量生成驗證碼的示例

以上就是python基于opencv批量生成驗證碼的示例的詳細內容,更多關于python 批量生成驗證碼的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 醴陵市| 沅陵县| 纳雍县| 彭水| 柳林县| 灵台县| 鄂州市| 碌曲县| 淮南市| 仪陇县| 徐汇区| 土默特右旗| 巴中市| 乌什县| 洛浦县| 剑阁县| 大渡口区| 陇川县| 兖州市| 晋州市| 桂林市| 红原县| 卓资县| 屏东县| 庆安县| 巴东县| 健康| 北流市| 右玉县| 周宁县| 上思县| 万源市| 米林县| 延吉市| 辽阳市| 阜康市| 荣成市| 高阳县| 砚山县| 鲁山县| 阜宁县|