赞
踩
import cv2 import os import numpy as np from numpy.linalg import norm from args import args import time class StatModel(object): def load(self, fn): self.model = self.model.load(fn) def save(self, fn): self.model.save(fn) class SVM(StatModel): def __init__(self, C=1, gamma=0.5): self.model = cv2.ml.SVM_create() self.model.setGamma(gamma) self.model.setC(C) self.model.setKernel(cv2.ml.SVM_RBF) self.model.setType(cv2.ml.SVM_C_SVC) # 不能保证包括所有省份 # 训练svm def train(self, samples, responses): self.model.train(samples, cv2.ml.ROW_SAMPLE, responses) # 调用svm def predict(self, samples): r = self.model.predict(samples) return r[1].ravel() # 定义参数 SZ = 20 # 训练图片长宽 L = 136 W = 36 # MAX_WIDTH = args.MAX_WIDTH # 原始图片最大宽度 # Min_Area = args.Min_Area # 车牌区域允许最大面积 # PROVINCE_START = args.PROVINCE_START # provinces = args.provinces # 来自opencv的sample,用于svm训练 def deskew(img): m = cv2.moments(img) if abs(m['mu02']) < 1e-2: return img.copy() skew = m['mu11'] / m['mu02'] M
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。