common.h 1.6 KB

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. #include <opencv2/opencv.hpp>
  3. #include "../Identifier/schema_struct.h"
  4. #include <vector>
  5. template<class T> void caculateLocateArea(const cv::Mat& img_rotated, const std::vector<T> matrixs, std::vector<identify::schema::ISCH_IDENTIFY_AREA>& assistLocateArea){
  6. if(matrixs.size()>0)
  7. {
  8. int oldsize=assistLocateArea.size();
  9. assistLocateArea.resize(assistLocateArea.size()+matrixs.size());
  10. for (int i=0;i<matrixs.size();i++)
  11. {
  12. const T & area = matrixs[i];
  13. assistLocateArea[oldsize+i].locate_area.centerx =area.centerx;
  14. assistLocateArea[oldsize+i].locate_area.centery =area.centery;
  15. assistLocateArea[oldsize+i].locate_area.width =area.width;
  16. assistLocateArea[oldsize+i].locate_area.height =area.height;
  17. assistLocateArea[oldsize+i].locate_area.nID =area.nID;
  18. int left =cv::max(0,cvRound(area.centerx-area.width/2.0-50)),
  19. top=cv::max(0,cvRound(area.centery-area.height/2.0-50)),
  20. right=cv::min(img_rotated.cols-1,cvRound(area.centerx+area.width/2.0+50)),
  21. bottom=cv::min(img_rotated.rows-1,cvRound(area.centery+area.height/2.0+50));
  22. assistLocateArea[oldsize+i].locateAreasOffset =cvPoint(left,top);
  23. Mat m_m = img_rotated(cvRect(left,top,right-left+1,bottom-top+1));
  24. Ptr<SurfFeatureDetector> pDetector=SurfFeatureDetector::create();// 这里我们用了SURF特征点
  25. pDetector->detect(m_m, assistLocateArea[oldsize+i].locateAreasKeyPoints);
  26. Ptr<SurfDescriptorExtractor> pExtractor = SurfDescriptorExtractor::create(); // 提取SURF描述向量
  27. pExtractor->compute(m_m, assistLocateArea[oldsize+i].locateAreasKeyPoints, assistLocateArea[oldsize+i].locateAreasDescriptor);
  28. }
  29. }
  30. }