IDCardRecognitionSo.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "IDCardRecognitionSo.h"
  2. void* CreateIDCardRecognition()
  3. {
  4. try
  5. {
  6. return static_cast<void*>(new IDCardRecognitionLibs::IDCardRecognition());
  7. }
  8. catch (...)
  9. {
  10. // 处理异常
  11. return nullptr;
  12. }
  13. }
  14. void ReleaseIDCardRecognition(void* hIDCardRecognition)
  15. {
  16. if (hIDCardRecognition == nullptr) { return; }
  17. try
  18. {
  19. const auto iDCardRecognition = static_cast<IDCardRecognitionLibs::IDCardRecognition*>(hIDCardRecognition);
  20. iDCardRecognition->Dispose();
  21. delete iDCardRecognition;
  22. }
  23. catch (...)
  24. {
  25. return;
  26. }
  27. }
  28. bool LoadNetWorks(void* hIDCardRecognition, ModelDataInfor modelDataInfor)
  29. {
  30. if (hIDCardRecognition == nullptr) { return false; }
  31. try{
  32. const auto iDCardRecognition = static_cast<IDCardRecognitionLibs::IDCardRecognition*>(hIDCardRecognition);
  33. bool status = iDCardRecognition->LoadNetWorks(modelDataInfor);
  34. return status;
  35. }
  36. catch (...)
  37. {
  38. return false;
  39. }
  40. }
  41. IDCardRecogResult EvaluateOneImage(void* hIDCardRecognition, ImageInfo imgInfor)
  42. {
  43. if (hIDCardRecognition == nullptr) { return IDCardRecogResult(); }
  44. const auto iDCardRecognition = static_cast<IDCardRecognitionLibs::IDCardRecognition*>(hIDCardRecognition);
  45. IDCardRecogResult result;
  46. try
  47. {
  48. //// 记录开始时间点
  49. //auto start = std::chrono::high_resolution_clock::now();
  50. iDCardRecognition->EvaluateOneImage(imgInfor, result);
  51. //// 记录结束时间点 计算时间差
  52. //auto end = std::chrono::high_resolution_clock::now();
  53. //auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
  54. //auto duration_ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration); // 将微秒转换为毫秒
  55. //result.TimeSpan = duration_ms.count();
  56. return result;
  57. }
  58. catch (std::exception& excep)
  59. {
  60. return IDCardRecogResult(); // 表示失败.
  61. }
  62. }