update code

This commit is contained in:
jackyu
2017-09-27 19:12:53 +08:00
parent 28e900ee66
commit babc8d53fc
2846 changed files with 53 additions and 51 deletions
Binary file not shown.
Binary file not shown.
+3 -3
View File
@@ -48,7 +48,7 @@ def v_rot(img,angel,shape,max_angel):
M = cv2.getPerspectiveTransform(pts1,pts2);
dst = cv2.warpPerspective(img,M,size);
return dst;
return dst,M;
def skew_detection(image_gray):
h, w = image_gray.shape[:2]
@@ -90,8 +90,8 @@ def fastDeskew(image):
print "校正角度 h ",skew_h,"v",skew_v
deskew = v_rot(image,int((90-skew_v)*1.5),image.shape,60)
return deskew
deskew,M = v_rot(image,int((90-skew_v)*1.5),image.shape,60)
return deskew,M
Binary file not shown.
Binary file not shown.
+3 -2
View File
@@ -66,7 +66,7 @@ def findContoursAndDrawBoundingBox(image_rgb):
pts_map2 = np.float32([[136,36],[0,36],[136,0],[0,0]])
mat = cv2.getPerspectiveTransform(pts_map1,pts_map2)
image = cv2.warpPerspective(rgb,mat,(136,36),flags=cv2.INTER_CUBIC)
image = deskew.fastDeskew(image)
image,M = deskew.fastDeskew(image)
return image
@@ -125,6 +125,7 @@ def findContoursAndDrawBoundingBox2(image_rgb):
pts_map2 = np.float32([[136,36],[0,36],[136,0],[0,0]])
mat = cv2.getPerspectiveTransform(pts_map1,pts_map2)
image = cv2.warpPerspective(rgb,mat,(136,36),flags=cv2.INTER_CUBIC)
image = deskew.fastDeskew(image)
image,M= deskew.fastDeskew(image)
return image
Binary file not shown.
+1 -3
View File
@@ -8,8 +8,6 @@ import numpy as np
import cv2
def getModel():
input = Input(shape=[12, 50, 3]) # change this shape to [None,None,3] to enable arbitraty shape input
x = Conv2D(10, (3, 3), strides=1, padding='valid', name='conv1')(input)
x = PReLU(shared_axes=[1, 2], name='prelu1')(x)
@@ -25,7 +23,7 @@ def getModel():
return model
model = getModel()
model.load_weights("./model/model12.h5")
# model.load_weights("./model/model12.h5")
def finemappingVertical(image):
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -221,7 +221,7 @@ def SimpleRecognizePlate(image):
if len(val)==3:
blocks, res, confidence = val
if confidence/7>0.7:
image = drawRectBox(image,rect,res)
# image = drawRectBox(image,rect,res)
res_set.append(res)
for i,block in enumerate(blocks):
Binary file not shown.
+13 -15
View File
@@ -1,7 +1,7 @@
#coding=utf-8
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D
from keras.layers import Conv2D,MaxPool2D
from keras.optimizers import SGD
from keras import backend as K
@@ -46,17 +46,15 @@ def Getmodel_tensorflow(nb_classes):
# weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先
model = Sequential()
model.add(Convolution2D(32, 5, 5,
border_mode='valid',
input_shape=(img_rows, img_cols,1)))
model.add(Conv2D(32, (5, 5),input_shape=(img_rows, img_cols,1)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Dropout(0.25))
model.add(Convolution2D(32, 3, 3))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Dropout(0.25))
model.add(Convolution2D(512, 3, 3))
model.add(Conv2D(512, (3, 3)))
# model.add(Activation('relu'))
# model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
# model.add(Dropout(0.25))
@@ -91,17 +89,15 @@ def Getmodel_ch(nb_classes):
# weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先
model = Sequential()
model.add(Convolution2D(32, 5, 5,
border_mode='valid',
input_shape=(img_rows, img_cols,1)))
model.add(Conv2D(32, (5, 5),input_shape=(img_rows, img_cols,1)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Dropout(0.25))
model.add(Convolution2D(32, 3, 3))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Dropout(0.25))
model.add(Convolution2D(512, 3, 3))
model.add(Conv2D(512, (3, 3)))
# model.add(Activation('relu'))
# model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
# model.add(Dropout(0.25))
@@ -124,7 +120,9 @@ model = Getmodel_tensorflow(65)
model_ch = Getmodel_ch(31)
model_ch.load_weights("./model/char_chi_sim.h5")
# model_ch.save_weights("./model/char_chi_sim.h5")
model.load_weights("./model/char_rec.h5")
# model.save("./model/char_rec.h5")
def SimplePredict(image,pos):
Binary file not shown.
+12 -13
View File
@@ -15,7 +15,7 @@ import scipy.signal as l
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D
from keras.layers import Conv2D, MaxPool2D
from keras.optimizers import SGD
from keras import backend as K
@@ -37,14 +37,12 @@ def Getmodel_tensorflow(nb_classes):
# weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先
model = Sequential()
model.add(Convolution2D(nb_filters, nb_conv, nb_conv,
border_mode='valid',
input_shape=(img_rows, img_cols,1)))
model.add(Conv2D(nb_filters, (nb_conv, nb_conv),input_shape=(img_rows, img_cols,1)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(Convolution2D(nb_filters, nb_conv, nb_conv))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Conv2D(nb_filters, (nb_conv, nb_conv)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Flatten())
model.add(Dense(256))
model.add(Dropout(0.5))
@@ -74,14 +72,12 @@ def Getmodel_tensorflow_light(nb_classes):
# weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先
model = Sequential()
model.add(Convolution2D(nb_filters, nb_conv, nb_conv,
border_mode='valid',
input_shape=(img_rows, img_cols, 1)))
model.add(Conv2D(nb_filters, (nb_conv, nb_conv),input_shape=(img_rows, img_cols, 1)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(Convolution2D(nb_filters, nb_conv * 2, nb_conv * 2))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Conv2D(nb_filters, (nb_conv * 2, nb_conv * 2)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Flatten())
model.add(Dense(32))
# model.add(Dropout(0.25))
@@ -102,7 +98,9 @@ model2 = Getmodel_tensorflow(3)
import os
model.load_weights("./model/char_judgement1.h5")
# model.save("./model/char_judgement1.h5")
model2.load_weights("./model/char_judgement.h5")
# model2.save("./model/char_judgement.h5")
model = model2
@@ -119,6 +117,7 @@ def get_median(data):
data[0] = median
return data[0]
import time
def searchOptimalCuttingPoint(rgb,res_map,start,width_boundingbox,interval_range):
t0 = time.time()
#
Binary file not shown.
+4 -5
View File
@@ -1,7 +1,7 @@
#coding=utf-8
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D
from keras.layers import Conv2D, MaxPool2D
from keras.optimizers import SGD
from keras import backend as K
@@ -30,11 +30,9 @@ def Getmodel_tensorflow(nb_classes):
# weight = dict(zip(range(3063), weight / weight.mean())) # 调整权重,高频字优先
model = Sequential()
model.add(Convolution2D(16, 5, 5,
border_mode='valid',
input_shape=(img_rows, img_cols,3)))
model.add(Conv2D(16, (5, 5),input_shape=(img_rows, img_cols,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool)))
model.add(MaxPool2D(pool_size=(nb_pool, nb_pool)))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation('relu'))
@@ -48,6 +46,7 @@ def Getmodel_tensorflow(nb_classes):
model = Getmodel_tensorflow(5)
model.load_weights("./model/plate_type.h5")
model.save("./model/plate_type.h5")
def SimplePredict(image):
image = cv2.resize(image, (34, 9))
image = image.astype(np.float) / 255
Binary file not shown.