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.

benchmark.py 2.4 kB

7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #coding=utf-8
  2. import os
  3. import numpy as np
  4. import cv2
  5. import json
  6. from hyperlpr import pipline as pp
  7. import sys
  8. from Levenshtein import StringMatcher as sm
  9. reload(sys)
  10. sys.setdefaultencoding("utf-8")
  11. # parent= "/Users/yujinke/车牌图片/云南车牌"
  12. parent= "/Users/yujinke/车牌图片/收费站_完成标注"
  13. # parent= "./cache/bad2"
  14. def comparestring(a,b):
  15. g = 0
  16. if len(a) == len(b):
  17. for x,y in zip(a,b):
  18. if x!=y:
  19. g+=1
  20. return g
  21. count = 0 ;
  22. count_p = 0
  23. count_d = 0
  24. count_lev = 0
  25. count_undetected = 0
  26. roi = [470,400,650,580]
  27. for filename in os.listdir(parent):
  28. path = os.path.join(parent,filename)
  29. print path
  30. if path.endswith(".jpg") or path.endswith(".png"):
  31. ics,name = os.path.split(path)
  32. name,ext = name.split(".")
  33. image = cv2.imread(path)
  34. image = image[roi[1]:roi[1]+roi[3],roi[0]:roi[0]+roi[2]]
  35. # cv2.imshow("test",image)
  36. # cv2.waitKey(0)
  37. info,dataset = pp.SimpleRecognizePlate(image)
  38. ext = ext.strip()
  39. name = name.strip()
  40. if len(dataset)==0:
  41. count_undetected +=1
  42. # cv2.imwrite("./cache/bad2/" + name + ".png", image)
  43. for one in dataset:
  44. # p = sm.StringMatcher(seq1=one.encode("utf-8"),seq2=name.encode("utf-8"))
  45. A = one.encode("utf-8")
  46. B = name.encode("utf-8")
  47. print one.encode("utf-8"),"<->",name.encode("utf-8"),"编辑距离:",comparestring(A,B)
  48. if comparestring(A,B)<2:
  49. count_lev+=1
  50. if one.encode("utf-8") == name.encode("utf-8"):
  51. count_p+=1
  52. break
  53. else:
  54. print "error",one.encode("utf-8"), name.encode("utf-8")
  55. count_d+=1
  56. # cv2.imshow("image",image)
  57. # cv2.waitKey(0)
  58. cv2.imwrite("./cache/bad2/"+name+".png",image)
  59. break
  60. count+=1
  61. print count_p / float(count),"编辑距离[1]:",count_lev/float(count),u"识出",count_p,u"总数",count,u"未识出",count_d,u"未检测出",count_undetected
  62. if count_p+count_d+count_undetected!=count:
  63. print dataset,len(dataset)
  64. exit(0)
  65. #
  66. # cv2.imshow("image",image)
  67. # cv2.waitKey(0)
  68. # print count_p/float(count)

高性能开源中文车牌识别框架