CrossDetector.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include "stdafx.h"
  3. #include <vector>
  4. #include <opencv/cv.h>
  5. #include <opencv/cxcore.h>
  6. #include <opencv/highgui.h>
  7. #include <opencv2/opencv.hpp>
  8. #include "schema_struct.h"
  9. #ifdef IDENTIFIER_EXPORTS
  10. #define IDENTIFIER_API __declspec(dllexport)
  11. #else
  12. #define IDENTIFIER_API __declspec(dllimport)
  13. #endif
  14. using namespace identify::schema;
  15. struct CvCross{
  16. int sign;
  17. int x;
  18. int y;
  19. int arg;
  20. };
  21. enum SIGND{
  22. SIGND_TL = DIR_FLAG_UP | DIR_FLAG_LEFT,
  23. SIGND_TR = DIR_FLAG_UP | DIR_FLAG_RIGHT,
  24. SIGND_TLR = DIR_FLAG_UP | DIR_FLAG_LEFT | DIR_FLAG_RIGHT,
  25. SIGND_BL = DIR_FLAG_DOWN | DIR_FLAG_LEFT,
  26. SIGND_BR = DIR_FLAG_DOWN | DIR_FLAG_RIGHT,
  27. SIGND_BLR = DIR_FLAG_DOWN | DIR_FLAG_LEFT | DIR_FLAG_RIGHT,
  28. SIGND_TBL = DIR_FLAG_UP | DIR_FLAG_DOWN | DIR_FLAG_LEFT,
  29. SIGND_TBR = DIR_FLAG_UP | DIR_FLAG_DOWN | DIR_FLAG_RIGHT,
  30. SIGND_TBLR = DIR_FLAG_UP | DIR_FLAG_DOWN | DIR_FLAG_LEFT | DIR_FLAG_RIGHT,
  31. };
  32. class IDENTIFIER_API CCrossDetector
  33. {
  34. private:
  35. struct SIGN
  36. {
  37. int x;
  38. int y;
  39. SIGND sign;
  40. };
  41. public:
  42. CCrossDetector(int unit_count = 15, double angle = 0, double angle_unit = 0.5, int cross_break = 4, int cross_burr = 15, int grayvalve = 180, int cross_len = 20, int cross_percent = 80);
  43. ~CCrossDetector(void);
  44. int Detect(const IplImage*img, std::vector<CvCross>&cross);
  45. private:
  46. bool isSign(const IplImage * img_binary, int x, int y, SIGN &sign_);
  47. bool isSignPossable(const IplImage * img_binary, int x, int y);
  48. private:
  49. double * dx[4];
  50. double * dy[4];
  51. int unit_count;
  52. double angle_unit;
  53. double angle;
  54. int total_angle_count;
  55. std::vector<int> arglist_t;
  56. std::vector<double> buffer_t;
  57. double* buffer;
  58. int* arglist;
  59. struct{
  60. //灰度阀值
  61. int m_CrossGray;
  62. //检测范围
  63. int m_CrossArg;
  64. //交叉点的长度
  65. int m_CrossLen;
  66. //最大断点长度
  67. int m_CrossBreak;
  68. //毛刺
  69. int m_CrossBurr;
  70. //周围空白百分比
  71. int m_CrossPercent;
  72. }options;
  73. };