- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我一直在使用 EMGU CV 库中的 SURF 特征检测示例。
到目前为止,它的效果非常好;我可以检测到 2 个给定图像之间的匹配对象,但我遇到了关于图像何时不匹配的问题。
我一直在寻求论坛的支持,但他们与我所在的位置相去甚远。谁知道哪些参数决定图像是否匹配。当我测试 2 张不匹配的图像时,代码仍然像存在匹配一样继续进行,即使没有匹配,也会在图像的随机位置绘制一条模糊的粗红线。
如果没有匹配项,我希望中断代码,不再继续。
附录:
static void Run()
{
Image<Gray, Byte> modelImage = new Image<Gray, byte>("HatersGonnaHate.png");
Image<Gray, Byte> observedImage = new Image<Gray, byte>("box_in_scene.png");
Stopwatch watch;
HomographyMatrix homography = null;
SURFDetector surfCPU = new SURFDetector(500, false);
VectorOfKeyPoint modelKeyPoints;
VectorOfKeyPoint observedKeyPoints;
Matrix<int> indices;
Matrix<float> dist;
Matrix<byte> mask;
if (GpuInvoke.HasCuda)
{
GpuSURFDetector surfGPU = new GpuSURFDetector(surfCPU.SURFParams, 0.01f);
using (GpuImage<Gray, Byte> gpuModelImage = new GpuImage<Gray, byte>(modelImage))
//extract features from the object image
using (GpuMat<float> gpuModelKeyPoints = surfGPU.DetectKeyPointsRaw(gpuModelImage, null))
using (GpuMat<float> gpuModelDescriptors = surfGPU.ComputeDescriptorsRaw(gpuModelImage, null, gpuModelKeyPoints))
using (GpuBruteForceMatcher matcher = new GpuBruteForceMatcher(GpuBruteForceMatcher.DistanceType.L2))
{
modelKeyPoints = new VectorOfKeyPoint();
surfGPU.DownloadKeypoints(gpuModelKeyPoints, modelKeyPoints);
watch = Stopwatch.StartNew();
// extract features from the observed image
using (GpuImage<Gray, Byte> gpuObservedImage = new GpuImage<Gray, byte>(observedImage))
using (GpuMat<float> gpuObservedKeyPoints = surfGPU.DetectKeyPointsRaw(gpuObservedImage, null))
using (GpuMat<float> gpuObservedDescriptors = surfGPU.ComputeDescriptorsRaw(gpuObservedImage, null, gpuObservedKeyPoints))
using (GpuMat<int> gpuMatchIndices = new GpuMat<int>(gpuObservedDescriptors.Size.Height, 2, 1))
using (GpuMat<float> gpuMatchDist = new GpuMat<float>(gpuMatchIndices.Size, 1))
{
observedKeyPoints = new VectorOfKeyPoint();
surfGPU.DownloadKeypoints(gpuObservedKeyPoints, observedKeyPoints);
matcher.KnnMatch(gpuObservedDescriptors, gpuModelDescriptors, gpuMatchIndices, gpuMatchDist, 2, null);
indices = new Matrix<int>(gpuMatchIndices.Size);
dist = new Matrix<float>(indices.Size);
gpuMatchIndices.Download(indices);
gpuMatchDist.Download(dist);
mask = new Matrix<byte>(dist.Rows, 1);
mask.SetValue(255);
Features2DTracker.VoteForUniqueness(dist, 0.8, mask);
int nonZeroCount = CvInvoke.cvCountNonZero(mask);
if (nonZeroCount >= 4)
{
nonZeroCount = Features2DTracker.VoteForSizeAndOrientation(modelKeyPoints, observedKeyPoints, indices, mask, 1.5, 20);
if (nonZeroCount >= 4)
homography = Features2DTracker.GetHomographyMatrixFromMatchedFeatures(modelKeyPoints, observedKeyPoints, indices, mask, 3);
}
watch.Stop();
}
}
}
else
{
//extract features from the object image
modelKeyPoints = surfCPU.DetectKeyPointsRaw(modelImage, null);
//MKeyPoint[] kpts = modelKeyPoints.ToArray();
Matrix<float> modelDescriptors = surfCPU.ComputeDescriptorsRaw(modelImage, null, modelKeyPoints);
watch = Stopwatch.StartNew();
// extract features from the observed image
observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedImage, null);
Matrix<float> observedDescriptors = surfCPU.ComputeDescriptorsRaw(observedImage, null, observedKeyPoints);
BruteForceMatcher matcher = new BruteForceMatcher(BruteForceMatcher.DistanceType.L2F32);
matcher.Add(modelDescriptors);
int k = 2;
indices = new Matrix<int>(observedDescriptors.Rows, k);
dist = new Matrix<float>(observedDescriptors.Rows, k);
matcher.KnnMatch(observedDescriptors, indices, dist, k, null);
mask = new Matrix<byte>(dist.Rows, 1);
mask.SetValue(255);
Features2DTracker.VoteForUniqueness(dist, 0.8, mask);
int nonZeroCount = CvInvoke.cvCountNonZero(mask);
if (nonZeroCount >= 4)
{
nonZeroCount = Features2DTracker.VoteForSizeAndOrientation(modelKeyPoints, observedKeyPoints, indices, mask, 1.5, 20);
if (nonZeroCount >= 4)
homography = Features2DTracker.GetHomographyMatrixFromMatchedFeatures(modelKeyPoints, observedKeyPoints, indices, mask, 3);
}
watch.Stop();
}
//Draw the matched keypoints
Image<Bgr, Byte> result = Features2DTracker.DrawMatches(modelImage, modelKeyPoints, observedImage, observedKeyPoints,
indices, new Bgr(255, 255, 255), new Bgr(255, 255, 255), mask, Features2DTracker.KeypointDrawType.NOT_DRAW_SINGLE_POINTS);
#region draw the projected region on the image
if (homography != null)
{ //draw a rectangle along the projected model
Rectangle rect = modelImage.ROI;
PointF[] pts = new PointF[] {
new PointF(rect.Left, rect.Bottom),
new PointF(rect.Right, rect.Bottom),
new PointF(rect.Right, rect.Top),
new PointF(rect.Left, rect.Top)};
homography.ProjectPoints(pts);
result.DrawPolyline(Array.ConvertAll<PointF, Point>(pts, Point.Round), true, new Bgr(Color.Red), 5);
}
#endregion
ImageViewer.Show(result, String.Format("Matched using {0} in {1} milliseconds", GpuInvoke.HasCuda ? "GPU" : "CPU", watch.ElapsedMilliseconds));
}
}
}
`
最佳答案
我不确定是否有适合所有图像序列或所有几何变形情况的方法。
我建议你计算PSNR在两个图像之间,并研究图像序列的容差阈值。
关于c# - EMGU CV SURF图像匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9740724/
我使用的是 Emgu 2(使用 opencv 2.4.10.1 的那个),它运行非常稳定,不会崩溃。我现在已经升级到 Emgu 3.1.0.1,我的应用程序有时会在几小时或一天内崩溃并出现 Acces
您好,我想做的是将 Emgu.CV.Mat 分配给 Emgu.CV.UI.ImageBox 但我一直收到 CvInvokeCore.cs 文件中的 System.AccessViolationExce
我在 C# 中使用 EmguCV,当我想从网络摄像头抓取帧时遇到问题,语句中出现红色下划线: imgOrg = capturecam.QueryFrame(); error: Cannot impli
我能够将 emgu 图像格式转换为字节字符串,这确实可以使用此代码保存在 MySQL 数据库上,但图像以 Windows 图像查看器无法识别的格式保存 string myCon
我有点碰壁我可能只是对如何在 .net(c# express 2010)中设置项目缺乏一些基本的了解,但我似乎无法让这个程序工作 基本上,我正在尝试设置一个简单的程序,该程序将获取网络摄像头馈送并检查
我正在使用 EmguCV 3.1 开发人脸识别应用程序。我正在使用 EigenFaceRecognizer 作为识别算法。我尝试使用以下代码训练图像。 List> trainingImages
我正在开发一个使用 OpenCV 库的项目,它使用 Emgu.CV.Image 作为从相机捕获的图像。 我正在尝试将代码移动到 Microsoft Azure 辅助角色中以处理云中的图像处理。 我当前
我从以下位置下载 sift 实现:https://sites.google.com/site/btabibian/projects/3d-reconstruction/code但我收到错误消息:命名空
我正在尝试使用EmguCV检测字符标记,并且已经从OpenCV网站复制并重写了example。 我的代码如下所示: Mat cameraMatrix = new Mat(new Size(3, 3),
我正在使用 Emgu CV 库用 Visual Basic 语言编写一些代码。 我需要知道如何使用函数 AdaptiveThreshold Dim inputImage As Emgu.CV.Inpu
我仍在学习 Emgu CV,我需要从包含 PNG32 数据的字节数组中加载图像。我正在按如下方式加载图像(这是工作示例): FileStream fs; Bitmap bitmap; Image im
我正在做一个项目,需要从表面的红外激光中识别点。我用的是带红外滤镜的相机 一些输入图像: 也可以有几个点。因此,我尝试从网络摄像头中锐化此图像,然后使用Emgu CV的FindContours方法。
我正在使用 emgu/opencv 来查找一些扁平 Blob 的位置。我目前可以以像素为单位找到它们的位置,并希望将其转换为世界坐标(in/mm)。我看过 emgu 的相机校准 example ,但我
我正在使用 Emgu 在 Visual Studio 上使用 C#。 我正在对一张大图像进行一些图像处理。我想到了将图像分成两半,并行进行操作,然后合并图像。 为了实现这一目标,我发现了一些关于获取图
我无法使用 Emgu CV 播放视频 显示错误 Unable to create capture from 184.avi 代码如下: public partial class Form1 : For
我正在从事一个实验项目,其中的挑战是识别和提取用户点击/触摸的图标或控件的图像。我正在尝试的方法如下(我需要一些帮助来完成第 3 步): 1) 当用户点击/触摸屏幕时截屏: 2) 应用边缘检测: 3)
我发现了一个类似的问题:creating histogram using emgu cv c# 当我传递灰度图像时效果很好,但是当我使用 Matrix 时,程序会抛出异常。我的代码: Matrix m
有人可以指导我介绍各向异性扩散的一些现有实现方式,最好是 perona-malik扩散吗? 最佳答案 翻译以下MATLAB代码: % pm2.m - Anisotropic Diffusion rou
我在项目中使用emgu。 我得到这个异常(exception): 这里是异常的细节: opencv_core242在文件夹项目中,并且平台目标设置为x86。 任何想法可能导致异常的原因以及如何解决?
今天是个好日子, 我正在尝试为视频构建实时帧插值程序。 因为我一直使用C#,所以我选择将OpenCV与Emgu 3.2.0(可用的最新版本)一起使用。 就是这样: 首先,我有2张分别名为frame1和
我是一名优秀的程序员,十分优秀!