12345678910111213141516171819202122232425262728293031 |
- #pragma once
- #include <opencv2/opencv.hpp>
- #include "../Identifier/schema_struct.h"
- #include <vector>
- template<class T> void caculateLocateArea(const cv::Mat& img_rotated, const std::vector<T> matrixs, std::vector<identify::schema::ISCH_IDENTIFY_AREA>& assistLocateArea){
- if(matrixs.size()>0)
- {
- int oldsize=assistLocateArea.size();
- assistLocateArea.resize(assistLocateArea.size()+matrixs.size());
- for (int i=0;i<matrixs.size();i++)
- {
- const T & area = matrixs[i];
- assistLocateArea[oldsize+i].locate_area.centerx =area.centerx;
- assistLocateArea[oldsize+i].locate_area.centery =area.centery;
- assistLocateArea[oldsize+i].locate_area.width =area.width;
- assistLocateArea[oldsize+i].locate_area.height =area.height;
- assistLocateArea[oldsize+i].locate_area.nID =area.nID;
- int left =cv::max(0,cvRound(area.centerx-area.width/2.0-50)),
- top=cv::max(0,cvRound(area.centery-area.height/2.0-50)),
- right=cv::min(img_rotated.cols-1,cvRound(area.centerx+area.width/2.0+50)),
- bottom=cv::min(img_rotated.rows-1,cvRound(area.centery+area.height/2.0+50));
- assistLocateArea[oldsize+i].locateAreasOffset =cvPoint(left,top);
- Mat m_m = img_rotated(cvRect(left,top,right-left+1,bottom-top+1));
- Ptr<SurfFeatureDetector> pDetector=SurfFeatureDetector::create();// 这里我们用了SURF特征点
- pDetector->detect(m_m, assistLocateArea[oldsize+i].locateAreasKeyPoints);
- Ptr<SurfDescriptorExtractor> pExtractor = SurfDescriptorExtractor::create(); // 提取SURF描述向量
- pExtractor->compute(m_m, assistLocateArea[oldsize+i].locateAreasKeyPoints, assistLocateArea[oldsize+i].locateAreasDescriptor);
-
- }
- }
- }
|