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.cpp 3.9 kB

7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Created by 庾金科 on 23/10/2017.
  3. //
  4. #include "Pipeline.h"
  5. namespace pr {
  6. const int HorizontalPadding = 4;
  7. PipelinePR::PipelinePR(std::string detector_filename,
  8. std::string finemapping_prototxt, std::string finemapping_caffemodel,
  9. std::string segmentation_prototxt, std::string segmentation_caffemodel,
  10. std::string charRecognization_proto, std::string charRecognization_caffemodel,
  11. std::string segmentationfree_proto,std::string segmentationfree_caffemodel) {
  12. plateDetection = new PlateDetection(detector_filename);
  13. fineMapping = new FineMapping(finemapping_prototxt, finemapping_caffemodel);
  14. plateSegmentation = new PlateSegmentation(segmentation_prototxt, segmentation_caffemodel);
  15. generalRecognizer = new CNNRecognizer(charRecognization_proto, charRecognization_caffemodel);
  16. segmentationFreeRecognizer = new SegmentationFreeRecognizer(segmentationfree_proto,segmentationfree_caffemodel);
  17. }
  18. PipelinePR::~PipelinePR() {
  19. delete plateDetection;
  20. delete fineMapping;
  21. delete plateSegmentation;
  22. delete generalRecognizer;
  23. delete segmentationFreeRecognizer;
  24. }
  25. std::vector<PlateInfo> PipelinePR:: RunPiplineAsImage(cv::Mat plateImage,int method) {
  26. std::vector<PlateInfo> results;
  27. std::vector<pr::PlateInfo> plates;
  28. plateDetection->plateDetectionRough(plateImage,plates,36,700);
  29. for (pr::PlateInfo plateinfo:plates) {
  30. cv::Mat image_finemapping = plateinfo.getPlateImage();
  31. image_finemapping = fineMapping->FineMappingVertical(image_finemapping);
  32. image_finemapping = pr::fastdeskew(image_finemapping, 5);
  33. //Segmentation-based
  34. if(method==SEGMENTATION_BASED_METHOD)
  35. {
  36. image_finemapping = fineMapping->FineMappingHorizon(image_finemapping, 2, HorizontalPadding);
  37. cv::resize(image_finemapping, image_finemapping, cv::Size(136+HorizontalPadding, 36));
  38. // cv::imshow("image_finemapping",image_finemapping);
  39. // cv::waitKey(0);
  40. plateinfo.setPlateImage(image_finemapping);
  41. std::vector<cv::Rect> rects;
  42. plateSegmentation->segmentPlatePipline(plateinfo, 1, rects);
  43. plateSegmentation->ExtractRegions(plateinfo, rects);
  44. cv::copyMakeBorder(image_finemapping, image_finemapping, 0, 0, 0, 20, cv::BORDER_REPLICATE);
  45. plateinfo.setPlateImage(image_finemapping);
  46. generalRecognizer->SegmentBasedSequenceRecognition(plateinfo);
  47. plateinfo.decodePlateNormal(pr::CH_PLATE_CODE);
  48. }
  49. //Segmentation-free
  50. else if(method==SEGMENTATION_FREE_METHOD)
  51. {
  52. image_finemapping = fineMapping->FineMappingHorizon(image_finemapping, 4, HorizontalPadding+3);
  53. cv::resize(image_finemapping, image_finemapping, cv::Size(136+HorizontalPadding, 36));
  54. // cv::imwrite("./test.png",image_finemapping);
  55. // cv::imshow("image_finemapping",image_finemapping);
  56. // cv::waitKey(0);
  57. plateinfo.setPlateImage(image_finemapping);
  58. // std::vector<cv::Rect> rects;
  59. std::pair<std::string,float> res = segmentationFreeRecognizer->SegmentationFreeForSinglePlate(plateinfo.getPlateImage(),pr::CH_PLATE_CODE);
  60. plateinfo.confidence = res.second;
  61. plateinfo.setPlateName(res.first);
  62. }
  63. results.push_back(plateinfo);
  64. }
  65. // for (auto str:results) {
  66. // std::cout << str << std::endl;
  67. // }
  68. return results;
  69. }//namespace pr
  70. }