IdentifyArea.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. typedef struct _IdentifyItem{
  3. float x, y, w, h;
  4. char name[8];
  5. _IdentifyItem(){
  6. x = 0; y = 0; w = 0; h = 0;
  7. memset(name, 0, sizeof(name) / sizeof(char));
  8. }
  9. }IdentifyItem;
  10. typedef struct _IdentifyGroup{
  11. bool mul; //是否是多选题
  12. char id[16]; // 题号
  13. int item_count; // 选项个数
  14. IdentifyItem* ptr_item;
  15. int *select;
  16. int select_count; //单选 1, 多选 n
  17. void init(int count, const char*id, bool mul){
  18. item_count = count;
  19. this->mul = mul;
  20. strcpy(this->id, id);
  21. if (item_count > 0){
  22. ptr_item = new IdentifyItem[item_count];
  23. select = new int[item_count];
  24. memset(select, 0, sizeof(int)*item_count);
  25. select_count = 0;
  26. }
  27. }
  28. _IdentifyGroup(){
  29. ptr_item = nullptr;
  30. select = nullptr;
  31. }
  32. ~_IdentifyGroup(){
  33. if (item_count > 0){
  34. if (ptr_item)delete[] ptr_item; ptr_item = nullptr;
  35. if (select) delete[] select; select = nullptr;
  36. }
  37. }
  38. IdentifyItem* get_item_by_index(int index){
  39. if (index < item_count){
  40. return ptr_item + index;
  41. }
  42. else{
  43. return nullptr;
  44. }
  45. }
  46. }IdentifyGroup;
  47. enum class GROUP_TYPE_IDENTIFY
  48. {
  49. NONE,
  50. TIANTUKAOHAO,
  51. KEGUANTI,
  52. QUEKAO,
  53. XUANZUOTI,
  54. };
  55. enum class IMG_ROTATION {
  56. ROTATION_0 = 1, // 模板同方向
  57. ROTATION_90 = 2, // 逆时针90°
  58. ROTATION_180 = 4, // 倒置180°
  59. ROTATION_270 = 8, // 顺时针90°
  60. };
  61. typedef struct _IdentifyArea {
  62. GROUP_TYPE_IDENTIFY type;
  63. bool btiantu; // 是否是填涂
  64. IMG_ROTATION dir; // 答题卡方向 2021.12.22
  65. int thresholdV; // 是否使用传入的阈值作为阈值分割 0:内部自己计算 >0: 使用传入值 2021.12.22
  66. int group_count;
  67. IdentifyGroup*ptr_group;
  68. _IdentifyArea(int count, bool btiantu = false, IMG_ROTATION dir = IMG_ROTATION::ROTATION_0, int thv = 0) {
  69. this->btiantu = btiantu;
  70. group_count = count;
  71. this->dir = dir;
  72. this->thresholdV = thv;
  73. if (group_count > 0) {
  74. ptr_group = new IdentifyGroup[group_count];
  75. }
  76. }
  77. ~_IdentifyArea() {
  78. if (group_count > 0) {
  79. delete[] ptr_group;
  80. ptr_group = nullptr;
  81. }
  82. }
  83. IdentifyGroup* get_group_by_index(int index) {
  84. if (index < group_count) {
  85. return ptr_group + index;
  86. }
  87. else {
  88. return nullptr;
  89. }
  90. }
  91. }IdentifyArea;
  92. enum CodeType
  93. {
  94. CODE_UNKNOW = 0, /// 未知类型
  95. CODE_QR = 1, /// 二维码类型
  96. CODE_BAR = 2, /// 条码类型
  97. };
  98. __declspec(dllimport) int api_ttpd_analysis_part(cv::Mat&image, IdentifyArea * pArea);
  99. __declspec(dllimport) int api_parse_barcode_qrcode(cv::Mat _img, int type, char * szRes, int size);
  100. std::string get_str_by_identify_group(int omr_out_type, IdentifyGroup*ptr_group, char option_spacer);