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.2 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
7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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= "you folder"
  12. def comparestring(a,b):
  13. g = 0
  14. if len(a) == len(b):
  15. for x,y in zip(a,b):
  16. if x!=y:
  17. g+=1
  18. return g
  19. count = 0 ;
  20. count_p = 0
  21. count_d = 0
  22. count_lev = 0
  23. count_undetected = 0
  24. roi = [470,400,650,580]
  25. for filename in os.listdir(parent):
  26. path = os.path.join(parent,filename)
  27. print path
  28. if path.endswith(".jpg") or path.endswith(".png"):
  29. ics,name = os.path.split(path)
  30. name,ext = name.split(".")
  31. image = cv2.imread(path)
  32. image = image[roi[1]:roi[1]+roi[3],roi[0]:roi[0]+roi[2]]
  33. # cv2.imshow("test",image)
  34. # cv2.waitKey(0)
  35. info,dataset = pp.SimpleRecognizePlate(image)
  36. ext = ext.strip()
  37. name = name.strip()
  38. if len(dataset)==0:
  39. count_undetected +=1
  40. # cv2.imwrite("./cache/bad2/" + name + ".png", image)
  41. for one in dataset:
  42. # p = sm.StringMatcher(seq1=one.encode("utf-8"),seq2=name.encode("utf-8"))
  43. A = one.decode("utf-8")
  44. B = name.decode("utf-8")
  45. print one.decode("utf-8"),"<->",name.decode("utf-8"),"编辑距离:",comparestring(A,B)
  46. if comparestring(A,B)<3:
  47. count_lev+=1
  48. else:
  49. cv2.imwrite("./cache/bad2/"+B+"->"+A+".png",image)
  50. if one.decode("utf-8") == name.decode("utf-8"):
  51. count_p+=1
  52. break
  53. else:
  54. print "error",one.decode("utf-8"), name.decode("utf-8")
  55. count_d+=1
  56. # cv2.imshow("image",image)
  57. # cv2.waitKey(0)
  58. # break
  59. count+=1
  60. print count_p / float(count),"编辑距离[1]:",count_lev/float(count),u"识出",count_p,u"总数",count,u"未识出",count_d,u"未检测出",count_undetected
  61. if count_p+count_d+count_undetected!=count:
  62. print dataset,len(dataset)
  63. # exit(0)