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.

main.cpp 3.4 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
5 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Created by Coleflowers on 20/06/2018.
  3. // Updated by Justid on 02/07/2018.
  4. //
  5. #include <phpcpp.h>
  6. #include <iostream>
  7. #include "PlateSegmentation.h"
  8. #include "CNNRecognizer.h"
  9. #include "Recognizer.h"
  10. #include "PlateDetection.h"
  11. #include "FastDeskew.h"
  12. #include "FineMapping.h"
  13. #include "Pipeline.h"
  14. /* 关闭原opencv报错输出 */
  15. int handleError( int status, const char* func_name,
  16. const char* err_msg, const char* file_name,
  17. int line, void* userdata )
  18. {
  19. //Do nothing -- will suppress console output
  20. return 0; //Return value is not used
  21. }
  22. /**
  23. * 车牌图片识别
  24. * @params imgpath 图片的绝对路径
  25. * @params modelpath 识别模型所在文件夹路径
  26. * @params confidence 可信度要求,可选参数,默认值0.75
  27. * @return 车牌号 图片路径的图片不存在的话 返回空值
  28. */
  29. cv::String scan(std::string imgpath, std::string modelpath, double confidence){
  30. cv::redirectError(handleError);
  31. try {
  32. pr::PipelinePR prc(modelpath+"/cascade.xml",
  33. modelpath+"/HorizonalFinemapping.prototxt",modelpath+"/HorizonalFinemapping.caffemodel",
  34. modelpath+"/Segmentation.prototxt",modelpath+"/Segmentation.caffemodel",
  35. modelpath+"/CharacterRecognization.prototxt",modelpath+"/CharacterRecognization.caffemodel",
  36. modelpath+"/SegmenationFree-Inception.prototxt",modelpath+"/SegmenationFree-Inception.caffemodel"
  37. );
  38. cv::Mat image = cv::imread(imgpath);
  39. std::vector<pr::PlateInfo> res = prc.RunPiplineAsImage(image,pr::SEGMENTATION_FREE_METHOD);
  40. cv::String platenum = "";
  41. for(auto st:res) {
  42. if(st.confidence>confidence) {
  43. platenum = st.getPlateName();
  44. break;
  45. }
  46. }
  47. return platenum;
  48. }
  49. catch( cv::Exception& e )
  50. {
  51. const char* err_msg = e.what();
  52. throw Php::Exception(err_msg);
  53. }
  54. }
  55. Php::Value funcWrapper(Php::Parameters &params) {
  56. // 图片路径
  57. std::string img = params[0];
  58. // 模型路径(文件夹)
  59. std::string model = params[1];
  60. // 可信度要求
  61. double confidence = 0.75;
  62. if (params.size() == 3){
  63. confidence = (double)params[2];
  64. }
  65. cv::String res = scan(img, model, confidence);
  66. return res.c_str();
  67. }
  68. /**
  69. * tell the compiler that the get_module is a pure C function
  70. */
  71. extern "C" {
  72. /**
  73. * Function that is called by PHP right after the PHP process
  74. * has started, and that returns an address of an internal PHP
  75. * strucure with all the details and features of your extension
  76. *
  77. * @return void* a pointer to an address that is understood by PHP
  78. */
  79. PHPCPP_EXPORT void *get_module() {
  80. // static(!) Php::Extension object that should stay in memory
  81. // for the entire duration of the process (that's why it's static)
  82. static Php::Extension extension("platescan", "1.0");
  83. // @todo add your own functions, classes, namespaces to the extension
  84. extension.add<funcWrapper>("platescan", {
  85. Php::ByVal("imgpath", Php::Type::String, true),
  86. Php::ByVal("modelpath", Php::Type::String, true),
  87. Php::ByVal("confidence", Php::Type::Float, false)
  88. });
  89. // return the extension
  90. return extension;
  91. }
  92. }