import os from random import randrange import numpy as np from PIL import Image, ImageDraw, ImageFont from sklearn import svm import cv2 as cv from matplotlib import pyplot as plt import pandas as pd width, height = 20, 40 fontSize = 40 noiseRate = 0.01 def generateDigits(dstDir='temp', num=40000): dstDir = 'temp' if not os.path.isdir(dstDir): os.mkdir(dstDir) with open(dstDir+'\\digits.txt', 'w') as fp: for i in range(num): digit = str(randrange(10)) im = Image.new('L', (width, height), 255) imDraw = ImageDraw.Draw(im) font = ImageFont.truetype(r"C:\Windows\Fonts\simsun.ttc", fontSize) imDraw.text((0,0), digit, font=font) for j in range(int(noiseRate*width*height)): w, h = randrange(1, width-1), randrange(height) c1 = im.getpixel((w, h))
sklearn SVM机器学习_数字识别
最新推荐文章于 2022-05-23 10:51:43 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)