Merged the trunk r8907, r8908

This commit is contained in:
Andrey Kamaev
2012-07-02 14:12:34 +00:00
parent af912f4843
commit aa911275c3
6 changed files with 74 additions and 50 deletions

View File

@@ -1,10 +1,10 @@
import numpy as np
import cv2
import digits
import os
import video
from common import mosaic
from digits import *
def main():
@@ -15,11 +15,9 @@ def main():
print '"%s" not found, run digits.py first' % classifier_fn
return
model = digits.SVM()
model = SVM()
model.load('digits_svm.dat')
SZ = 20
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
@@ -55,13 +53,12 @@ def main():
A[:,:2] = np.eye(2)*s
A[:,2] = t
sub1 = cv2.warpAffine(sub, A, (SZ, SZ), flags=cv2.WARP_INVERSE_MAP | cv2.INTER_LINEAR)
sub1 = digits.deskew(sub1)
sub1 = deskew(sub1)
if x+w+SZ < frame.shape[1] and y+SZ < frame.shape[0]:
frame[y:,x+w:][:SZ, :SZ] = sub1[...,np.newaxis]
sample = np.float32(sub1).reshape(1,SZ*SZ) / 255.0
sample = preprocess_hog([sub1])
digit = model.predict(sample)[0]
cv2.putText(frame, '%d'%digit, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.0, (200, 0, 0), thickness = 1)