异常未处理:Emgu.CV.Util.CvException:'OpenCV: '
Exception Unhandled : Emgu.CV.Util.CvException: 'OpenCV: '
我正在尝试在实时视频流中的两个帧之间找到匹配的关键点。但是我遇到了“未处理的异常”错误。以下是错误详情:Error Details
这是我的 class 问题:
public static VectorOfKeyPoint[] Matches(List<Mat> imList)
{
int k = 2;
double uniquenessT = 0.8;
Mat homography = new Mat();
Mat mask = new Mat();
VectorOfKeyPoint modelKeyPoints = new VectorOfKeyPoint();
VectorOfKeyPoint observedKeyPoints = new VectorOfKeyPoint();
VectorOfVectorOfDMatch matches = new VectorOfVectorOfDMatch();
using (UMat uModelImage = imList[0].GetUMat(Emgu.CV.CvEnum.AccessType.Read))
using (UMat uObservedImage = imList[1].GetUMat(Emgu.CV.CvEnum.AccessType.Read))
{
FastFeatureDetector fastCPU = new FastFeatureDetector(10, true);
UMat modelDescriptors = new UMat();
fastCPU.DetectAndCompute(uModelImage, null, modelKeyPoints, modelDescriptors, false);
UMat observedDescriptors = new UMat();
fastCPU.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, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
mask.SetTo(new MCvScalar(255));
Features2DToolbox.VoteForUniqueness(matches, uniquenessT, 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);
}
VectorOfKeyPoint[] result = null;
if (homography != null)
{
result[0] = modelKeyPoints;
result[1] = observedKeyPoints;
}
return result;
}
}
´´´
感谢您的帮助。
感谢所有让我自己解决问题的人。
代码上有改动。
using(ORBDetector detector = new ORBDetector())
{
detector.DetectAndCompute(uModelImage, null, modelKeyPoints, modelDescriptors, false);
detector.DetectAndCompute(uObservedImage, null, observedKeyPoints,
observedDescriptors, false);
我正在尝试在实时视频流中的两个帧之间找到匹配的关键点。但是我遇到了“未处理的异常”错误。以下是错误详情:Error Details
这是我的 class 问题:
public static VectorOfKeyPoint[] Matches(List<Mat> imList)
{
int k = 2;
double uniquenessT = 0.8;
Mat homography = new Mat();
Mat mask = new Mat();
VectorOfKeyPoint modelKeyPoints = new VectorOfKeyPoint();
VectorOfKeyPoint observedKeyPoints = new VectorOfKeyPoint();
VectorOfVectorOfDMatch matches = new VectorOfVectorOfDMatch();
using (UMat uModelImage = imList[0].GetUMat(Emgu.CV.CvEnum.AccessType.Read))
using (UMat uObservedImage = imList[1].GetUMat(Emgu.CV.CvEnum.AccessType.Read))
{
FastFeatureDetector fastCPU = new FastFeatureDetector(10, true);
UMat modelDescriptors = new UMat();
fastCPU.DetectAndCompute(uModelImage, null, modelKeyPoints, modelDescriptors, false);
UMat observedDescriptors = new UMat();
fastCPU.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, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
mask.SetTo(new MCvScalar(255));
Features2DToolbox.VoteForUniqueness(matches, uniquenessT, 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);
}
VectorOfKeyPoint[] result = null;
if (homography != null)
{
result[0] = modelKeyPoints;
result[1] = observedKeyPoints;
}
return result;
}
}
´´´
感谢您的帮助。
感谢所有让我自己解决问题的人。 代码上有改动。
using(ORBDetector detector = new ORBDetector())
{
detector.DetectAndCompute(uModelImage, null, modelKeyPoints, modelDescriptors, false);
detector.DetectAndCompute(uObservedImage, null, observedKeyPoints,
observedDescriptors, false);