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 2.6 kB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // Created by Jack Yu on 20/09/2017.
  3. //
  4. #ifndef HYPERPR_PLATEINFO_H
  5. #define HYPERPR_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, INVALID };
  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,
  17. PlateColor plateType) {
  18. licensePlate = plateData;
  19. name = plateName;
  20. ROI = plateRect;
  21. Type = plateType;
  22. }
  23. PlateInfo(const cv::Mat &plateData, cv::Rect plateRect,
  24. PlateColor plateType) {
  25. licensePlate = plateData;
  26. ROI = plateRect;
  27. Type = plateType;
  28. }
  29. PlateInfo(const cv::Mat &plateData, cv::Rect plateRect) {
  30. licensePlate = plateData;
  31. ROI = plateRect;
  32. }
  33. PlateInfo() {}
  34. cv::Mat getPlateImage() { return licensePlate; }
  35. void setPlateImage(cv::Mat plateImage) { licensePlate = plateImage; }
  36. cv::Rect getPlateRect() { return ROI; }
  37. void setPlateRect(cv::Rect plateRect) { ROI = plateRect; }
  38. cv::String getPlateName() { return name; }
  39. void setPlateName(cv::String plateName) { name = plateName; }
  40. int getPlateType() { return Type; }
  41. void appendPlateChar(const std::pair<CharType, cv::Mat> &plateChar) {
  42. plateChars.push_back(plateChar);
  43. }
  44. void appendPlateCoding(const std::pair<CharType, cv::Mat> &charProb) {
  45. plateCoding.push_back(charProb);
  46. }
  47. std::string decodePlateNormal(std::vector<std::string> mappingTable) {
  48. std::string decode;
  49. for (auto plate : plateCoding) {
  50. float *prob = (float *)plate.second.data;
  51. if (plate.first == CHINESE) {
  52. decode += mappingTable[std::max_element(prob, prob + 31) - prob];
  53. confidence += *std::max_element(prob, prob + 31);
  54. }
  55. else if (plate.first == LETTER) {
  56. decode += mappingTable[std::max_element(prob + 41, prob + 65) - prob];
  57. confidence += *std::max_element(prob + 41, prob + 65);
  58. }
  59. else if (plate.first == LETTER_NUMS) {
  60. decode += mappingTable[std::max_element(prob + 31, prob + 65) - prob];
  61. confidence += *std::max_element(prob + 31, prob + 65);
  62. } else if (plate.first == INVALID) {
  63. decode += '*';
  64. }
  65. }
  66. name = decode;
  67. confidence /= 7;
  68. return decode;
  69. }
  70. private:
  71. cv::Mat licensePlate;
  72. cv::Rect ROI;
  73. std::string name;
  74. PlateColor Type;
  75. };
  76. } // namespace pr
  77. #endif // HYPERPR_PLATEINFO_H