问题描述
- 【求助~~】opencv surf 如何计算两帧图片的重叠度是否>80%?
-
读取一个视频,获取相连两帧图片,需要计算它们的重叠度是否>80%IplImage* compOverlap(const IplImage* frameBefore, const IplImage* frameAfter)
{Mat matBefore(frameBefore); Mat matAfter(frameAfter); // 检测surf特征点 vector<KeyPoint> keypointsBefore, keypointsAfter; SurfFeatureDetector detector(400); detector.detect(matBefore, keypointsBefore); detector.detect(matAfter, keypointsAfter); //cout << "keypointsBefore size:" << keypointsBefore.size() << endl; //cout << "keypointsAfter size:" << keypointsAfter.size() << endl; // 描述surf特征点 SurfDescriptorExtractor surfDesc; Mat descriptros1, descriptros2; surfDesc.compute(matBefore, keypointsBefore, descriptros1); surfDesc.compute(matAfter, keypointsAfter, descriptros2); // 计算匹配点数 BruteForceMatcher<L2<float>>matcher; vector<DMatch> matches; int a = 0; matcher.match(descriptros1, descriptros2, matches); } 现我已经获取了matches,但是如何计算这两帧的重叠度? 初步想法是 循环判断特征点的欧式距离matches[m].distance, 计算特征点欧式距离>0.2的个数, 再除以对比帧frameAfter的特征点个数 如果结果<0.2,则认为重叠度>80% 但是感觉这个方法不太对, 新手刚接触opencv,希望各位大神不吝赐教啊~~ 感激不尽~~
解决方案
根据matches求出坐标变换参数,然后计算重叠度
时间: 2024-10-05 09:08:32