gpt4 book ai didi

c# - EmguCV-获取用于确定图像相似性的匹配数

转载 作者:行者123 更新时间:2023-12-02 16:44:38 29 4
gpt4 key购买 nike

我目前正在使用SURF算法(在EmguCV 3.1上)测试两个图像是否可能对应于同一位置Image 1及其非常暗的版本,这给我带来了以下两个问题:

1-您认为计算两张图片之间的匹配次数是否是确定图像相似性的好主意?如果没有,还有其他建议吗?

2-假设计算比赛次数是一种很好的方法。如何获得比赛数?一些文章谈论counting the number of NonZeros。但是,结果似乎不像this picture那样匹配,它仅显示2个匹配项,但返回的值为30(变量noZeroCount)。我正在使用的代码是这样的:

public static void FindMatch(Mat modelImage, Mat observedImage, out long matchTime, out VectorOfKeyPoint modelKeyPoints, out VectorOfKeyPoint observedKeyPoints, VectorOfVectorOfDMatch matches, out Mat mask, out Mat homography)
{
int k = 2;
double uniquenessThreshold = 0.8;
double hessianThresh = 300;

Stopwatch watch;
homography = null;

modelKeyPoints = new VectorOfKeyPoint();
observedKeyPoints = new VectorOfKeyPoint();
using (UMat uModelImage = modelImage.ToUMat(AccessType.Read))
using (UMat uObservedImage = observedImage.ToUMat(AccessType.Read))
{
SURF surfCPU = new SURF(hessianThresh, 4 , 2, true, true);

//extract features from the object image
UMat modelDescriptors = new UMat();
surfCPU.DetectAndCompute(uModelImage, null, modelKeyPoints, modelDescriptors, false);

watch = Stopwatch.StartNew();

// extract features from the observed image
UMat observedDescriptors = new UMat();
surfCPU.DetectAndCompute(uObservedImage, null, observedKeyPoints, observedDescriptors, false);
BFMatcher matcher = new BFMatcher(DistanceType.L2);
matcher.Add(modelDescriptors);

matcher.KnnMatch(observedDescriptors, matches, k, null);
mask = new Mat(matches.Size, 1, DepthType.Cv8U, 1);
mask.SetTo(new MCvScalar(255));
Features2DToolbox.VoteForUniqueness(matches, uniquenessThreshold, mask);

int nonZeroCount = CvInvoke.CountNonZero(mask);
if (nonZeroCount >= 4)
{
nonZeroCount = Features2DToolbox.VoteForSizeAndOrientation(modelKeyPoints, observedKeyPoints,
matches, mask, 1.5, 20);
if (nonZeroCount >= 4)
homography = Features2DToolbox.GetHomographyMatrixFromMatchedFeatures(modelKeyPoints,
observedKeyPoints, matches, mask, 2);
}

watch.Stop();
matchTime = watch.ElapsedMilliseconds;
}
}

非常感谢您的任何努力。

最佳答案

使用nonZeroCount时,此值越大,两个图像之间的相似度越高。

关于c# - EmguCV-获取用于确定图像相似性的匹配数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40889570/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com