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.

PlateInfo.h 3.7 kB

6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // Created by 庾金科 on 20/09/2017.
  3. //
  4. #ifndef SWIFTPR_PLATEINFO_H
  5. #define SWIFTPR_PLATEINFO_H
  6. #include <opencv2/opencv.hpp>
  7. namespace pr {
  8. typedef std::vector<cv::Mat> Character;
  9. enum PlateColor { BLUE, YELLOW, WHITE, GREEN, BLACK,UNKNOWN};
  10. enum CharType {CHINESE,LETTER,LETTER_NUMS};
  11. class PlateInfo {
  12. public:
  13. std::vector<std::pair<CharType,cv::Mat> > plateChars;
  14. std::vector<std::pair<CharType,cv::Mat> > plateCoding;
  15. float confidence = 0;
  16. PlateInfo(const cv::Mat &plateData, std::string plateName, cv::Rect plateRect, PlateColor plateType) {
  17. licensePlate = plateData;
  18. name = plateName;
  19. ROI = plateRect;
  20. Type = plateType;
  21. }
  22. PlateInfo(const cv::Mat &plateData, cv::Rect plateRect, PlateColor plateType) {
  23. licensePlate = plateData;
  24. ROI = plateRect;
  25. Type = plateType;
  26. }
  27. PlateInfo(const cv::Mat &plateData, cv::Rect plateRect) {
  28. licensePlate = plateData;
  29. ROI = plateRect;
  30. }
  31. PlateInfo() {
  32. }
  33. cv::Mat getPlateImage() {
  34. return licensePlate;
  35. }
  36. void setPlateImage(cv::Mat plateImage){
  37. licensePlate = plateImage;
  38. }
  39. cv::Rect getPlateRect() {
  40. return ROI;
  41. }
  42. void setPlateRect(cv::Rect plateRect) {
  43. ROI = plateRect;
  44. }
  45. cv::String getPlateName() {
  46. return name;
  47. }
  48. void setPlateName(cv::String plateName) {
  49. name = plateName;
  50. }
  51. int getPlateType() {
  52. return Type;
  53. }
  54. void appendPlateChar(const std::pair<CharType,cv::Mat> &plateChar)
  55. {
  56. plateChars.push_back(plateChar);
  57. }
  58. void appendPlateCoding(const std::pair<CharType,cv::Mat> &charProb){
  59. plateCoding.push_back(charProb);
  60. }
  61. // cv::Mat getPlateChars(int id) {
  62. // if(id<PlateChars.size())
  63. // return PlateChars[id];
  64. // }
  65. std::string decodePlateNormal(std::vector<std::string> mappingTable) {
  66. std::string decode;
  67. for(auto plate:plateCoding) {
  68. float *prob = (float *)plate.second.data;
  69. if(plate.first == CHINESE) {
  70. decode += mappingTable[std::max_element(prob,prob+31) - prob];
  71. confidence+=*std::max_element(prob,prob+31);
  72. // std::cout<<*std::max_element(prob,prob+31)<<std::endl;
  73. }
  74. if(plate.first == LETTER) {
  75. decode += mappingTable[std::max_element(prob+41,prob+65)- prob];
  76. confidence+=*std::max_element(prob+41,prob+65);
  77. }
  78. if(plate.first == LETTER_NUMS) {
  79. decode += mappingTable[std::max_element(prob+31,prob+65)- prob];
  80. confidence+=*std::max_element(prob+31,prob+65);
  81. // std::cout<<*std::max_element(prob+31,prob+65)<<std::endl;
  82. }
  83. }
  84. name = decode;
  85. confidence/=7;
  86. return decode;
  87. }
  88. private:
  89. cv::Mat licensePlate;
  90. cv::Rect ROI;
  91. std::string name;
  92. PlateColor Type;
  93. };
  94. }
  95. #endif //SWIFTPR_PLATEINFO_H