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.5 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
7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #
  22. # A = "赣FJ0368".decode("utf-8")
  23. # B = "琼WJ0368".decode("utf-8")
  24. # print "对比",comparestring(A,B)
  25. count = 0 ;
  26. count_p = 0
  27. count_d = 0
  28. count_lev = 0
  29. count_undetected = 0
  30. roi = [470,400,650,580]
  31. for filename in os.listdir(parent):
  32. path = os.path.join(parent,filename)
  33. print path
  34. if path.endswith(".jpg") or path.endswith(".png"):
  35. ics,name = os.path.split(path)
  36. name,ext = name.split(".")
  37. image = cv2.imread(path)
  38. image = image[roi[1]:roi[1]+roi[3],roi[0]:roi[0]+roi[2]]
  39. # cv2.imshow("test",image)
  40. # cv2.waitKey(0)
  41. info,dataset = pp.SimpleRecognizePlate(image)
  42. ext = ext.strip()
  43. name = name.strip()
  44. if len(dataset)==0:
  45. count_undetected +=1
  46. # cv2.imwrite("./cache/bad2/" + name + ".png", image)
  47. for one in dataset:
  48. # p = sm.StringMatcher(seq1=one.encode("utf-8"),seq2=name.encode("utf-8"))
  49. A = one.decode("utf-8")
  50. B = name.decode("utf-8")
  51. print one.decode("utf-8"),"<->",name.decode("utf-8"),"编辑距离:",comparestring(A,B)
  52. if comparestring(A,B)<3:
  53. count_lev+=1
  54. else:
  55. cv2.imwrite("./cache/bad2/"+B+"->"+A+".png",image)
  56. if one.decode("utf-8") == name.decode("utf-8"):
  57. count_p+=1
  58. break
  59. else:
  60. print "error",one.decode("utf-8"), name.decode("utf-8")
  61. count_d+=1
  62. # cv2.imshow("image",image)
  63. # cv2.waitKey(0)
  64. # break
  65. count+=1
  66. print count_p / float(count),"编辑距离[1]:",count_lev/float(count),u"识出",count_p,u"总数",count,u"未识出",count_d,u"未检测出",count_undetected
  67. if count_p+count_d+count_undetected!=count:
  68. print dataset,len(dataset)
  69. # exit(0)
  70. #
  71. # cv2.imshow("image",image)
  72. # cv2.waitKey(0)
  73. # print count_p/float(count)