From 2f6a4cca9b22a9d2ecac9a1ba4b7168dc87bf822 Mon Sep 17 00:00:00 2001 From: Marcus Universe Date: Sat, 30 Sep 2017 04:22:38 +0800 Subject: [PATCH] add configuration file and test example --- config.json | 15 ++++++++++ hyperlpr/config.py | 6 ++++ hyperlpr/plateStructure.py | 0 hyperlpr_test/detect_test.py | 58 ++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 config.json create mode 100644 hyperlpr/config.py create mode 100644 hyperlpr/plateStructure.py create mode 100644 hyperlpr_test/detect_test.py diff --git a/config.json b/config.json new file mode 100644 index 0000000..03e72f9 --- /dev/null +++ b/config.json @@ -0,0 +1,15 @@ +{ + "global":{ + "debug":true + }, + "log":{ + }, + "detect":{ + }, + "recognize":{ + }, + "detectTest":{ + "detectPath":"/Users/universe/Documents/work/data/Plate/boundingbox", + "outputPath":"/Users/universe/ProgramUniverse/python/Forked/HyperLPR/out/detect_test" + } +} \ No newline at end of file diff --git a/hyperlpr/config.py b/hyperlpr/config.py new file mode 100644 index 0000000..f249655 --- /dev/null +++ b/hyperlpr/config.py @@ -0,0 +1,6 @@ +import json + + + +with open("/Users/universe/ProgramUniverse/python/Forked/HyperLPR/config.json") as f: + configuration = json.load(f) diff --git a/hyperlpr/plateStructure.py b/hyperlpr/plateStructure.py new file mode 100644 index 0000000..e69de29 diff --git a/hyperlpr_test/detect_test.py b/hyperlpr_test/detect_test.py new file mode 100644 index 0000000..0b90327 --- /dev/null +++ b/hyperlpr_test/detect_test.py @@ -0,0 +1,58 @@ +import os +import hyperlpr.detect as hyperDetect +import hyperlpr.config as hyperConfig +import cv2 +import argparse +import sys + +parser = argparse.ArgumentParser() + +debugInfo = hyperConfig.configuration["global"]["debug"] +testPath = hyperConfig.configuration["detectTest"]["detectPath"] +outPath = hyperConfig.configuration["detectTest"]["outputPath"] + +def drawBoundingBox(originImage,rect): + cv2.rectangle(originImage, (int(rect[0]), int(rect[1])), (int(rect[0] + rect[2]), int(rect[1] + rect[3])), (0, 0, 255), 2, + cv2.LINE_AA) + return originImage + + +#detect Plate in image batch +def detectPlateBatchTest(filepath): + for filename in os.listdir(filepath): + if filename.endswith(".jpg") or filename.endswith(".png"): + fileFullPath = os.path.join(filepath,filename) + image = cv2.imread(fileFullPath) + image_c = image.copy() + Plates = hyperDetect.detectPlateRough(image_c, image_c.shape[0], top_bottom_padding_rate=0.1) + pathName = filename.split('.')[0] + if debugInfo: + if len(Plates) != 0: + if os.path.exists(os.path.join(outPath,pathName)) == False: + os.mkdir(os.path.join(outPath,pathName)) + for i,plate in enumerate(Plates): + rect = plate[1] + region = plate[2] + if debugInfo: + cv2.imwrite(os.path.join(outPath,pathName,"region_"+str(i)+"_"+pathName+".png"),region) + drawBoundingBox(image_c,rect) + if debugInfo: + cv2.imwrite(os.path.join(outPath,pathName,"out_"+pathName+".png"),image_c) + + +def main(args): + if args.type == 'batch': + detectPlateBatchTest(testPath) + else: + print "type: "+args.type+" not found!\n" + print parser.print_help() + + +def parse_arguments(argv): + parser.add_argument('--type',type=str,help='detect Plate type{batch},default is batch',default='batch') + return parser.parse_args(argv) + +if __name__ == "__main__": + main(parse_arguments(sys.argv[1:])) + + #detectPlateBatchTest(testPath)