资 源 简 介
SVM做的验证码识别,准确率85%# -*- coding: utf-8 -*
__author__ = "eple"
from svmutil import *
from PIL import Image
from numpy import *
import os
import string
def getFeatures(path):
features = []
im = array(Image.open(path).convert("L"))
h,w = shape(im)
for i in xrange(0,h):
for j in xrange(0,w):
im[i][j] = 0 if im[i][j] < 128 else 1
for i in xrange(1,h-1):
for j in xrange(1,w-1):
if im[i][j] != 0 and im[i-1][j]==0 and im[i][j-1]==0 and im[i][j+1]==0 and im[i+1][j]==0:
im[i][j] = 0
for rang in [xrange(2,8), xrange(12,18), xrange(22,28), xrange(32,38)]:
temp = []
for i in rang:
for j in xrange(0,10):
temp.append(im[j][i])
features.append(temp)
return features