c# - 使用特征检测时如何获取对象的位置?
问题描述
我是 Emgucv (c#) 的新程序员,我需要一些帮助。
我尝试使用特征检测并遵循示例(Emgu->emgucv-windesktop 4.0.1.3373 -> Emgu.CV.Example -> FeatureMatching)。它使用 Kaze 检测器来寻找特征。
我运行了这个例子,结果很好。(可以检测特征并给出特征区域)
但是,我尝试更改图像(新模型图像并观察从模型图像中裁剪的图像)
新结果可以检测到特征,但特征区域不正确。
我尝试同时使用彩色图像和灰度图像(已经更改 ImreadModes.ImageType )。
该区域仍然不正确。
那么,有人可以给我指导或解决方案吗?
/// <summary>
/// Draw the model image and observed image, the matched features and homography projection.
/// </summary>
/// <param name="modelImage">The model image</param>
/// <param name="observedImage">The observed image</param>
/// <param name="matchTime">The output total time for computing the homography matrix.</param>
/// <returns>The model image and observed image, the matched features and homography projection.</returns>
public static Mat Draw(Mat modelImage, Mat observedImage, out long matchTime)
{
Mat homography;
VectorOfKeyPoint modelKeyPoints;
VectorOfKeyPoint observedKeyPoints;
using (VectorOfVectorOfDMatch matches = new VectorOfVectorOfDMatch())
{
Mat mask;
FindMatch(modelImage, observedImage, out matchTime, out modelKeyPoints, out observedKeyPoints, matches,
out mask, out homography);
//Draw the matched keypoints
Mat result = new Mat();
Features2DToolbox.DrawMatches(modelImage, modelKeyPoints, observedImage, observedKeyPoints,
matches, result, new MCvScalar(255, 255, 255), new MCvScalar(255, 255, 255), mask);
#region draw the projected region on the image
if (homography != null)
{
//draw a rectangle along the projected model
Rectangle rect = new Rectangle(Point.Empty, modelImage.Size);
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)
};
pts = CvInvoke.PerspectiveTransform(pts, homography);
Point[] points = new Point[pts.Length];
for (int i = 0; i < points.Length; i++)
points[i] = Point.Round(pts[i]);
using (VectorOfPoint vp = new VectorOfPoint(points))
{
CvInvoke.Polylines(result, vp, true, new MCvScalar(255, 0, 0, 255), 5);
}
}
#endregion
return result;
}
}
}
}
示例结果:https ://www.img.in.th/image/E9RweT
解决方案
推荐阅读
- python - 如何从重复的多行文件中获取模式
- java - 当特定的弹簧配置文件处于活动状态时,如何防止运行测试?
- angular - Angular 6 路由 - 根据父路由参数设置子路由组件
- peewee - 解决选择查询中的 SQLite 参数限制
- php - 如果它们在具有内联 css 属性的 div 内,如何在 php 中显示成功和错误消息 display:none
- shell - Pywal 没有在 crontab 上更改 GNOME 上的壁纸
- c# - 如何从 ASP.NET MVC 中的单元测试中分配 BaseController 值
- automation - 如何修复此“使用带有 contextId 的 'CLASS_NAME' 查找'android.widget.TextView':''多个:false”
- typescript - lambda函数中警告中的阴影变量
- javascript - 将两个图像与 JavaScript 合并为水印