You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

detect_test.py 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import os
  2. import hyperlpr.detect as hyperDetect
  3. import hyperlpr.config as hyperConfig
  4. import cv2
  5. import argparse
  6. import sys
  7. parser = argparse.ArgumentParser()
  8. debugInfo = hyperConfig.configuration["global"]["debug"]
  9. testPath = hyperConfig.configuration["detectTest"]["detectPath"]
  10. outPath = hyperConfig.configuration["detectTest"]["outputPath"]
  11. def drawBoundingBox(originImage,rect):
  12. cv2.rectangle(originImage, (int(rect[0]), int(rect[1])), (int(rect[0] + rect[2]), int(rect[1] + rect[3])), (0, 0, 255), 2,
  13. cv2.LINE_AA)
  14. return originImage
  15. #detect Plate in image batch
  16. def detectPlateBatchTest(filepath):
  17. for filename in os.listdir(filepath):
  18. if filename.endswith(".jpg") or filename.endswith(".png"):
  19. fileFullPath = os.path.join(filepath,filename)
  20. image = cv2.imread(fileFullPath)
  21. image_c = image.copy()
  22. Plates = hyperDetect.detectPlateRough(image_c, image_c.shape[0], top_bottom_padding_rate=0.1)
  23. pathName = filename.split('.')[0]
  24. if debugInfo:
  25. if len(Plates) != 0:
  26. if os.path.exists(os.path.join(outPath,pathName)) == False:
  27. os.mkdir(os.path.join(outPath,pathName))
  28. for i,plate in enumerate(Plates):
  29. rect = plate[1]
  30. region = plate[2]
  31. if debugInfo:
  32. cv2.imwrite(os.path.join(outPath,pathName,"region_"+str(i)+"_"+pathName+".png"),region)
  33. drawBoundingBox(image_c,rect)
  34. if debugInfo:
  35. cv2.imwrite(os.path.join(outPath,pathName,"out_"+pathName+".png"),image_c)
  36. def main(args):
  37. if args.type == 'batch':
  38. detectPlateBatchTest(testPath)
  39. else:
  40. print "type: "+args.type+" not found!\n"
  41. print parser.print_help()
  42. def parse_arguments(argv):
  43. parser.add_argument('--type',type=str,help='detect Plate type{batch},default is batch',default='batch')
  44. return parser.parse_args(argv)
  45. if __name__ == "__main__":
  46. main(parse_arguments(sys.argv[1:]))
  47. #detectPlateBatchTest(testPath)