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.

Pipeline.h 3.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // Created by �׽�� on 22/10/2017.
  3. //
  4. #ifndef SWIFTPR_PIPLINE_H
  5. #define SWIFTPR_PIPLINE_H
  6. #include "PlateDetection.h"
  7. #include "PlateSegmentation.h"
  8. #include "CNNRecognizer.h"
  9. #include "PlateInfo.h"
  10. #include "FastDeskew.h"
  11. #include "FineMapping.h"
  12. #include "Recognizer.h"
  13. namespace pr{
  14. class PipelinePR{
  15. public:
  16. GeneralRecognizer *generalRecognizer;
  17. PlateDetection *plateDetection;
  18. PlateSegmentation *plateSegmentation;
  19. FineMapping *fineMapping;
  20. PipelinePR(std::string detector_filename,
  21. std::string finemapping_prototxt, std::string finemapping_caffemodel,
  22. std::string segmentation_prototxt, std::string segmentation_caffemodel,
  23. std::string charRecognization_proto, std::string charRecognization_caffemodel
  24. ) {
  25. plateDetection = new PlateDetection(detector_filename);
  26. fineMapping = new FineMapping(finemapping_prototxt, finemapping_caffemodel);
  27. plateSegmentation = new PlateSegmentation(segmentation_prototxt, segmentation_caffemodel);
  28. generalRecognizer = new CNNRecognizer(charRecognization_proto, charRecognization_caffemodel);
  29. }
  30. ~PipelinePR() {
  31. delete plateDetection;
  32. delete fineMapping;
  33. delete plateSegmentation;
  34. delete generalRecognizer;
  35. }
  36. std::vector<std::string> chars_code{ "京","沪","津","渝","冀","晋","蒙","辽","吉","黑","苏","浙","皖","闽","赣","鲁","豫","鄂","湘","粤","桂","琼","川","贵","云","藏","陕","甘","青","宁","新","0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z" };
  37. std::vector<std::string> plateRes;
  38. std::vector<PlateInfo> RunPiplineAsImage(cv::Mat plateImage) {
  39. std::vector<PlateInfo> results;
  40. std::vector<pr::PlateInfo> plates;
  41. plateDetection->plateDetectionRough(plateImage, plates);
  42. for (pr::PlateInfo plateinfo : plates) {
  43. cv::Mat image_finemapping = plateinfo.getPlateImage();
  44. image_finemapping = fineMapping->FineMappingVertical(image_finemapping);
  45. image_finemapping = pr::fastdeskew(image_finemapping, 5);
  46. image_finemapping = fineMapping->FineMappingHorizon(image_finemapping, 2, 5);
  47. cv::resize(image_finemapping, image_finemapping, cv::Size(136, 36));
  48. plateinfo.setPlateImage(image_finemapping);
  49. std::vector<cv::Rect> rects;
  50. plateSegmentation->segmentPlatePipline(plateinfo, 1, rects);
  51. plateSegmentation->ExtractRegions(plateinfo, rects);
  52. cv::copyMakeBorder(image_finemapping, image_finemapping, 0, 0, 0, 20, cv::BORDER_REPLICATE);
  53. plateinfo.setPlateImage(image_finemapping);
  54. generalRecognizer->SegmentBasedSequenceRecognition(plateinfo);
  55. plateinfo.decodePlateNormal(chars_code);
  56. results.push_back(plateinfo);
  57. std::cout << plateinfo.getPlateName() << std::endl;
  58. }
  59. // for (auto str:results) {
  60. // std::cout << str << std::endl;
  61. // }
  62. return results;
  63. }
  64. };
  65. }
  66. #endif //SWIFTPR_PIPLINE_H