コード例 #1
0
ファイル: SVMtrain.py プロジェクト: BLKStone/EasyPyPR
def dirPicTest():

	clf = joblib.load('model/svm.pkl')
	print type(clf)
	print clf

	platePath = 'resource/general_test'
	for root, dirs, files in os.walk( platePath ):
		print len(files)	
		for file in files:
			path = os.path.join( root, file )
			print 'loading....',path
			imgPlate = cv2.imread(path,cv2.IMREAD_COLOR)
			PlateLocater.m_debug = False
			Result = PlateLocater.fuzzyLocate(imgPlate)

			for plate in Result:
				
				feature = PlateJudger.getHistogramFeatures(plate)
				res = clf.predict(feature)
				
				flag = (res==1)
				print flag[0]

				if flag[0]:
					cv2.imshow('test',plate)
					cv2.waitKey(0)
					cv2.destroyAllWindows()

				
				


	return None
コード例 #2
0
ファイル: SVMtrain.py プロジェクト: BLKStone/EasyPyPR
def CV_dirPicTest():
	model = CV_trainModel()

	platePath = 'resource/general_test'
	for root, dirs, files in os.walk( platePath ):
		print len(files)	
		for file in files:
			path = os.path.join( root, file )
			print 'loading....',path
			imgPlate = cv2.imread(path,cv2.IMREAD_COLOR)
			PlateLocater.m_debug = False
			Result = PlateLocater.fuzzyLocate(imgPlate)

			for plate in Result:
				
				feature = PlateJudger.getHistogramFeatures(plate)

				print feature.dtype

				feature = np.float32(feature)
				res = model.predict(feature)
				
				a = (res==1)
				print a[0]

				if a[0]:
					cv2.imshow('test',plate)
					cv2.waitKey(0)
					cv2.destroyAllWindows()
コード例 #3
0
def features(inMat, sizeData):
    # 抠取中间区域
    center_rect = getCenterRect(inMat)
    x, y, w, h = center_rect
    roi = inMat[y:y + h, x:x + w]

    # low data feature
    low_data = cv2.resize(roi, (sizeData, sizeData))

    VERTICAL = 0
    HORIZONTAL = 1
    # Histogram feature
    vhist = PlateJudger.ProjectedHistogram(low_data, VERTICAL)
    hhist = PlateJudger.ProjectedHistogram(low_data, HORIZONTAL)

    # print vhist.shape
    # print hhist.shape
    # print low_data

    numCols = vhist.shape[1] + hhist.shape[
        1] + low_data.shape[0] * low_data.shape[1]
    outMat = np.zeros((1, numCols))

    # feature,ANN的样本特征为水平、垂直直方图和低分辨率图像所组成的矢量
    index = 0
    for i in range(0, vhist.shape[1]):
        outMat[0, index] = vhist[0, i]
        index += 1

    # print outMat

    for i in range(0, hhist.shape[1]):
        outMat[0, index] = hhist[0, i]
        index += 1

    for i in range(0, low_data.shape[0]):
        for j in range(0, low_data.shape[0]):
            outMat[0, index] = low_data[i, j]
            index += 1

    return outMat
コード例 #4
0
ファイル: SVMtrain.py プロジェクト: BLKStone/EasyPyPR
def CV_PicTest():
	model = CV_trainModel()

	imgPlate = cv2.imread('plate_judge.jpg',cv2.IMREAD_COLOR)

	PlateLocater.m_debug = False
	Result = PlateLocater.fuzzyLocate(imgPlate)

	for plate in Result:
		cv2.imshow('test',plate)
		feature = PlateJudger.getHistogramFeatures(plate)
		feature = np.float32(feature)
		res = model.predict(feature)
		print res
		cv2.waitKey(0)
		cv2.destroyAllWindows()
コード例 #5
0
ファイル: PlateRecognizer.py プロジェクト: BLKStone/EasyPyPR
def plateRecognize(inMat):
    PlateLocater.m_debug = False
    CharsIndentifier.m_debug = False

    Result = PlateLocater.fuzzyLocate(inMat)

    if m_debug:
        print '候选车牌数量:',len(Result)
        index_loc = 0
        for img in Result:
            index_loc += 1
            cv2.imshow("候选车牌"+str(index_loc),img)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    resultVec = PlateJudger.platesJudge(Result)
    

    if m_debug:
        print 'SVM筛选后的车牌数量:',len(resultVec)
        index_loc = 0
        for img in resultVec:
            index_loc += 1
            cv2.imshow("SVM-"+str(index_loc),img)
            cv2.imwrite("debug/SVM-"+str(index_loc)+".jpg", img)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    lisences = list()
    for img_plate in resultVec:
        segmented = CharsSegmenter.charsSegment(img_plate)

        if m_debug:
            index_char = 0
            for char in segmented:
                index_char += 1
                cv2.imshow("chars_segment"+str(index_char), char)
                cv2.imwrite("debug/segmented-"+str(index_char)+".jpg", char)

            cv2.waitKey(0)
            cv2.destroyAllWindows()

        lisence = CharsIndentifier.identifyPlate(segmented)
        # print lisence
        lisences.append(lisence)

    return lisences
コード例 #6
0
ファイル: SVMtrain.py プロジェクト: BLKStone/EasyPyPR
def loadNegativeTrainData(platePath):

	traindata = np.ones((1,172))
	label = np.array([0])
	isFirst = True

	for root, dirs, files in os.walk( platePath ):
		print len(files)	
		for file in files:

			path = os.path.join( root, file )
			print 'loading....',path
			imgPlate = cv2.imread(path,cv2.IMREAD_COLOR)
			feature = PlateJudger.getHistogramFeatures(imgPlate)

			if isFirst:
				traindata = feature
				isFirst = False
			else:
				traindata = np.vstack([traindata,feature])
				label = np.hstack([label,0])

	return traindata,label
コード例 #7
0
ファイル: FunctionTest.py プロジェクト: BLKStone/EasyPyPR
def test_plate_locate():
    PlateLocater.m_debug = False
    rootdir = "resources/easy_test"
    print 'test_plate_locate'

    for parent,dirnames,filenames in os.walk(rootdir):        
        index_file = 0
        print filenames        
        for filename in filenames:
                cv2.destroyAllWindows()
                index_file += 1

                imgPlate = cv2.imread(os.path.join(parent,filename),cv2.IMREAD_COLOR)
                print '文件名:',filename.split('.')[0]

                cv2.imshow("原图",imgPlate)
                Result = PlateLocater.fuzzyLocate(imgPlate)
                print '候选车牌数量:',len(Result)

                index_loc = 0
                for img in Result:
                    index_loc += 1
                    cv2.imshow("候选车牌"+str(index_loc),img)
                cv2.waitKey(0)

                resultVec = PlateJudger.platesJudge(Result)
                print 'SVM筛选后的车牌数量:',len(resultVec)

                index_loc = 0
                for img in resultVec:
                    index_loc += 1
                    cv2.imshow("SVM-"+str(index_loc),img)
                cv2.waitKey(0)


                if index_file >20:
                     break
コード例 #8
0
ファイル: FunctionTest.py プロジェクト: BLKStone/EasyPyPR
def test_plate_locate():
    PlateLocater.m_debug = False
    rootdir = "resources/easy_test"
    print 'test_plate_locate'

    for parent, dirnames, filenames in os.walk(rootdir):
        index_file = 0
        print filenames
        for filename in filenames:
            cv2.destroyAllWindows()
            index_file += 1

            imgPlate = cv2.imread(os.path.join(parent, filename),
                                  cv2.IMREAD_COLOR)
            print '文件名:', filename.split('.')[0]

            cv2.imshow("原图", imgPlate)
            Result = PlateLocater.fuzzyLocate(imgPlate)
            print '候选车牌数量:', len(Result)

            index_loc = 0
            for img in Result:
                index_loc += 1
                cv2.imshow("候选车牌" + str(index_loc), img)
            cv2.waitKey(0)

            resultVec = PlateJudger.platesJudge(Result)
            print 'SVM筛选后的车牌数量:', len(resultVec)

            index_loc = 0
            for img in resultVec:
                index_loc += 1
                cv2.imshow("SVM-" + str(index_loc), img)
            cv2.waitKey(0)

            if index_file > 20:
                break