PageMatcher.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include <opencv2/opencv.hpp>
  3. #include <opencv2/xfeatures2d.hpp>
  4. #include "schema_struct.h"
  5. #include <vector>
  6. #include <boost/smart_ptr.hpp>
  7. #ifdef IDENTIFIER_EXPORTS
  8. #define IDENTIFIER_API __declspec(dllexport)
  9. #else
  10. #define IDENTIFIER_API __declspec(dllimport)
  11. #endif
  12. using namespace std;
  13. using namespace cv::xfeatures2d;
  14. using namespace identify::result;
  15. using namespace identify::schema;
  16. using namespace identify::analysis;
  17. namespace identify{
  18. class IDENTIFIER_API CPageMatcher
  19. {
  20. public:
  21. CPageMatcher(void);
  22. ~CPageMatcher(void);
  23. //设置模板信息
  24. void SetSchemaPages(boost::shared_ptr<const ISCH_Schema> schema);
  25. //识别指定图像
  26. int Identify(const IplImage* img, MATCH_REUSLT & match_result);
  27. //旋转指定角度后按照指定模板进行识别
  28. int Identifi(const IplImage * src, int shemaIndex, const int rotation, MATCH_REUSLT& result);
  29. private:
  30. //模板
  31. boost::shared_ptr<const ISCH_Schema>schemaPages;
  32. //防射变换(由模板变换到图像)
  33. Mat m_AffineTransform;
  34. //防射变换逆变换矩阵(由图像变换到模板)
  35. Mat m_AffineTransformInverseMatrix;
  36. double m_Scaler0;//存储当前页的缩放率
  37. int m_pageDirection;//存储当前识别页的旋转方向
  38. private:
  39. template<typename T1, typename T2 > double GetDistance(T1 point1, T2 point2);
  40. template<typename T1, typename T2> T2 warpAffinePoint(T1& src, Mat * map_matrix);
  41. /************************************************************************/
  42. /*图像基本信息检查,最小宽高限制,长宽比例限制 */
  43. /************************************************************************/
  44. inline int BaseCheck(const IplImage * src, const identify::schema::ISCH_SCHEMA_PAGE& schemaPage);
  45. //查找定位点定位信息
  46. int FindLoacteByLocatePoint(const IplImage * img, const identify::schema::ISCH_SCHEMA_PAGE& schemaPage, const double estimate_scale, const int rotation, vector<CvPoint2D32f> &relationKey, vector<CvPoint2D32f>& relationValue, vector<int> &relationIndex, int first_index);
  47. //查找模糊定位区定位信息
  48. int FindLoacteByLocateArea(const IplImage * img, const identify::schema::ISCH_SCHEMA_PAGE& schemaPage, const double estimate_scale, const int rotation, vector<CvPoint2D32f>& relationKey, vector<CvPoint2D32f>& relationValue, vector<int> &relationIndex, int first_index);
  49. //查找交叉点定位信息
  50. int FindLoacteByLocateCross(const IplImage * img, const identify::schema::ISCH_SCHEMA_PAGE& schemaPage, const double estimate_scale, const int rotation, vector<CvPoint2D32f>& relationKey, vector<CvPoint2D32f>& relationValue, vector<int> &relationIndex, int first_index);
  51. //匹配
  52. int ConfirmLocateInfo(vector<CvPoint2D32f>& relationKey, vector<CvPoint2D32f>& relationValue, int& inliner_count, cv::Mat& _inliner);
  53. //按照指定模板进行识别
  54. int Identifi(const IplImage * src, int shemaIndex, MATCH_REUSLT& match_result);
  55. };
  56. }