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.4 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // Created by Jack Yu on 23/10/2017.
  3. //
  4. #include "../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. plateinfo.setPlateImage(image_finemapping);
  39. std::vector<cv::Rect> rects;
  40. plateSegmentation->segmentPlatePipline(plateinfo, 1, rects);
  41. plateSegmentation->ExtractRegions(plateinfo, rects);
  42. cv::copyMakeBorder(image_finemapping, image_finemapping, 0, 0, 0, 20, cv::BORDER_REPLICATE);
  43. plateinfo.setPlateImage(image_finemapping);
  44. generalRecognizer->SegmentBasedSequenceRecognition(plateinfo);
  45. plateinfo.decodePlateNormal(pr::CH_PLATE_CODE);
  46. }
  47. //Segmentation-free
  48. else if(method==SEGMENTATION_FREE_METHOD)
  49. {
  50. image_finemapping = fineMapping->FineMappingHorizon(image_finemapping, 4, HorizontalPadding+3);
  51. cv::resize(image_finemapping, image_finemapping, cv::Size(136+HorizontalPadding, 36));
  52. plateinfo.setPlateImage(image_finemapping);
  53. std::pair<std::string,float> res = segmentationFreeRecognizer->SegmentationFreeForSinglePlate(plateinfo.getPlateImage(),pr::CH_PLATE_CODE);
  54. plateinfo.confidence = res.second;
  55. plateinfo.setPlateName(res.first);
  56. }
  57. results.push_back(plateinfo);
  58. }
  59. return results;
  60. }//namespace pr
  61. }