基本思路是使用opencv来把随机生成的字符,和随机生成的线段,放到一个随机生成的图像中去。

  虽然没有加复杂的形态学处理,但是目前看起来效果还不错

  尝试生成1000张图片,但是最后只有998张,因为有有重复的,被覆盖掉了。

  代码如下:

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 = ""
#生成一个随机矩阵,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()

  结果:

最新文章

  1. Android权限管理之Android 6.0运行时权限及解决办法
  2. 无法对 索引 'IndexName' 执行 删除,因为它不存在,或者您没有所需的权限。
  3. HTTP超文本传输协议-HTTP/1.1中文版
  4. Android 源码下载
  5. libyuv 编译 for android
  6. JS兼容IE浏览器的方法
  7. CSS命名规则
  8. VB操作CAD
  9. PDOstament对象执行execute()函数,只要是sql语句正确都是返回true
  10. Altium Designer中各层的含义
  11. 使用Cobertura统计JUnit测试覆盖率
  12. 深度学习框架Caffe的编译安装
  13. git 本地推送远程仓库报错: error: failed to push some refs to 'https://github.com/yangtuothink/mxonline.git'
  14. [51CTO]服务器虚拟化开源技术主流架构之争
  15. angularjs中templateUrl的路径问题
  16. 20155209 2016-2017-2 《Java程序设计》第八周学习总结
  17. 更改Request Parameters中的值
  18. 第三百零四节,Django框架,urls.py模块,views.py模块,路由映射与路由分发以及逻辑处理——url控制器
  19. 【题解】 AGC029-A Irreversible operation
  20. [转] ELK 之 Logstash

热门文章

  1. elasticsearch 深入 —— normalizer
  2. tensorflow创建cnn网络进行中文手写文字识别
  3. vue项目一个页面使用多个轮播图详解
  4. Spike Your CPU’s Processor in .Net
  5. Redis线上环境做Keys匹配操作!你可以离职了!
  6. 挖坑指南:iView-admin动态配置route.meta.title
  7. 02 spring security 自定义用户认证流程
  8. idea将本地项目推送到git远程库
  9. HTTP请求流程基础知识
  10. JS中数据结构之栈