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.

demo.py 1.7 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
5 years ago
7 years ago
7 years ago
7 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import sys
  2. reload(sys)
  3. sys.setdefaultencoding("utf-8")
  4. import time
  5. def SpeedTest(image_path):
  6. grr = cv2.imread(image_path)
  7. model = pr.LPR("model/cascade.xml", "model/model12.h5", "model/ocr_plate_all_gru.h5")
  8. model.SimpleRecognizePlateByE2E(grr)
  9. t0 = time.time()
  10. for x in range(20):
  11. model.SimpleRecognizePlateByE2E(grr)
  12. t = (time.time() - t0)/20.0
  13. print "Image size :" + str(grr.shape[1])+"x"+str(grr.shape[0]) + " need " + str(round(t*1000,2))+"ms"
  14. from PIL import ImageFont
  15. from PIL import Image
  16. from PIL import ImageDraw
  17. fontC = ImageFont.truetype("./Font/platech.ttf", 14, 0)
  18. def drawRectBox(image,rect,addText):
  19. cv2.rectangle(image, (int(rect[0]), int(rect[1])), (int(rect[0] + rect[2]), int(rect[1] + rect[3])), (0,0, 255), 2,cv2.LINE_AA)
  20. cv2.rectangle(image, (int(rect[0]-1), int(rect[1])-16), (int(rect[0] + 115), int(rect[1])), (0, 0, 255), -1,
  21. cv2.LINE_AA)
  22. img = Image.fromarray(image)
  23. draw = ImageDraw.Draw(img)
  24. draw.text((int(rect[0]+1), int(rect[1]-16)), addText.decode("utf-8"), (255, 255, 255), font=fontC)
  25. imagex = np.array(img)
  26. return imagex
  27. import HyperLPRLite as pr
  28. import cv2
  29. import numpy as np
  30. grr = cv2.imread("images_rec/2.jpg")
  31. model = pr.LPR("model/cascade.xml","model/model12.h5","model/ocr_plate_all_gru.h5")
  32. for pstr,confidence,rect in model.SimpleRecognizePlateByE2E(grr):
  33. if confidence>0.7:
  34. image = drawRectBox(grr, rect, pstr+" "+str(round(confidence,3)))
  35. print "plate_str:"
  36. print pstr
  37. print "plate_confidence"
  38. print confidence
  39. cv2.imshow("image",image)
  40. cv2.waitKey(0)
  41. #SpeedTest("images_rec/2.jpg")