OCRParameter.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // Copyright (c) 2021 raoyutian Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. using System.Runtime.InteropServices;
  15. //说明:OCRParameter类的属性定义顺序不可随便更改,需要与PaddleOCR中的OCRParameter顺序一致
  16. namespace PaddleOCRSharp
  17. {
  18. /// <summary>
  19. /// OCR识别参数
  20. /// </summary>
  21. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  22. public class OCRParameter
  23. {
  24. #region 通用参数
  25. /// <summary>
  26. /// 是否使用GPU;默认false
  27. /// </summary>
  28. [field: MarshalAs(UnmanagedType.I1)]
  29. public bool use_gpu { get; set; } = false;
  30. /// <summary>
  31. /// GPU id,使用GPU时有效;默认0;
  32. /// </summary>
  33. public int gpu_id { get; set; } = 0;
  34. /// <summary>
  35. /// 申请的GPU内存;默认4000
  36. /// </summary>
  37. public int gpu_mem { get; set; } = 4000;
  38. /// <summary>
  39. /// CPU预测时的线程数,在机器核数充足的情况下,该值越大,预测速度越快;默认10
  40. /// </summary>
  41. public int cpu_math_library_num_threads { get; set; } = 10;
  42. /// <summary>
  43. /// 是否使用mkldnn库;默认true
  44. /// </summary>
  45. [field:MarshalAs(UnmanagedType.I1)]
  46. public bool enable_mkldnn { get; set; } =true;
  47. #endregion
  48. #region 前向相关
  49. /// <summary>
  50. ///是否执行文字检测;默认true
  51. /// </summary>
  52. [field: MarshalAs(UnmanagedType.I1)]
  53. public bool det { get; set; } = true;
  54. /// <summary>
  55. /// 是否执行文字识别;默认true
  56. /// </summary>
  57. [field: MarshalAs(UnmanagedType.I1)]
  58. public bool rec { get; set; } = true;
  59. /// <summary>
  60. /// 是否执行文字方向分类;默认false
  61. /// </summary>
  62. [field: MarshalAs(UnmanagedType.I1)]
  63. public bool cls { get; set; } = false;
  64. #endregion
  65. #region 检测模型相关
  66. /// <summary>
  67. /// 输入图像长宽大于960时,等比例缩放图像,使得图像最长边为960,;默认960
  68. /// </summary>
  69. public int max_side_len { get; set; } = 960;
  70. /// <summary>
  71. /// 用于过滤DB预测的二值化图像,设置为0.-0.3对结果影响不明显;默认0.3
  72. /// </summary>
  73. public float det_db_thresh { get; set; } = 0.3f;
  74. /// <summary>
  75. /// DB后处理过滤box的阈值,如果检测存在漏框情况,可酌情减小;默认0.5
  76. /// </summary>
  77. public float det_db_box_thresh { get; set; } = 0.5f;
  78. /// <summary>
  79. /// 表示文本框的紧致程度,越小则文本框更靠近文本;默认1.6
  80. /// </summary>
  81. public float det_db_unclip_ratio { get; set; } = 1.6f;
  82. /// <summary>
  83. /// 是否在输出映射上使用膨胀,默认false
  84. /// </summary>
  85. [field: MarshalAs(UnmanagedType.I1)]
  86. public bool use_dilation { get; set; } = false;
  87. /// <summary>
  88. /// 1:使用多边形框计算bbox score,0:使用矩形框计算。矩形框计算速度更快,多边形框对弯曲文本区域计算更准确。
  89. /// </summary>
  90. [field: MarshalAs(UnmanagedType.I1)]
  91. public bool det_db_score_mode { get; set; } = true;
  92. /// <summary>
  93. /// 是否对结果进行可视化,为1时,预测结果会保存在output字段指定的文件夹下和输入图像同名的图像上。默认false
  94. /// </summary>
  95. [field: MarshalAs(UnmanagedType.I1)]
  96. public bool visualize { get; set; } = false;
  97. #endregion
  98. #region 方向分类器相关
  99. /// <summary>
  100. /// 是否使用方向分类器,默认false
  101. /// </summary>
  102. [field: MarshalAs(UnmanagedType.I1)]
  103. public bool use_angle_cls { get; set; } = false;
  104. /// <summary>
  105. /// 方向分类器的得分阈值,默认0.9
  106. /// </summary>
  107. public float cls_thresh { get; set; } = 0.9f;
  108. /// <summary>
  109. /// 方向分类器batchsize,默认1
  110. /// </summary>
  111. public int cls_batch_num { get; set; } = 1;
  112. #endregion
  113. #region 识别模型相关
  114. /// <summary>
  115. /// 识别模型batchsize,默认6
  116. /// </summary>
  117. public int rec_batch_num { get; set; } = 6;
  118. /// <summary>
  119. /// 识别模型输入图像高度,默认48
  120. /// </summary>
  121. public int rec_img_h { get; set; } = 48;
  122. /// <summary>
  123. /// 识别模型输入图像宽度,默认320
  124. /// </summary>
  125. public int rec_img_w { get; set; } = 320;
  126. #endregion
  127. /// <summary>
  128. /// 是否显示预测结果,默认false
  129. /// </summary>
  130. [field: MarshalAs(UnmanagedType.I1)]
  131. public bool show_img_vis { get; set; } = false;
  132. /// <summary>
  133. /// 使用GPU预测时,是否启动tensorrt,默认false
  134. /// </summary>
  135. [field: MarshalAs(UnmanagedType.I1)]
  136. public bool use_tensorrt { get; set; } = false;
  137. }
  138. }