EmguCV 跟踪器在 C# 中的实现
EmguCV Tracker implementation in C#
正在寻找示例代码以了解如何实施 EmguCV 跟踪器。我在这个写得不好的代码中尝试了一些东西:
class ObjectTracker
{
Emgu.CV.Tracking.TrackerCSRT tracker = new Emgu.CV.Tracking.TrackerCSRT();
bool isActive = false;
public bool trackerActive = false;
public void Track(Bitmap pic, Rectangle selection,out Rectangle bound)
{
Rectangle result = new Rectangle();
Bitmap bitmap=pic; //This is your bitmap
Emgu.CV.Image<Bgr, Byte> imageCV = new Emgu.CV.Image<Bgr, byte>(bitmap); //Image Class from Emgu.CV
Emgu.CV.Mat mat = imageCV.Mat; //This is your Image converted to Mat
if (tracker.Init(mat,selection))
{
while (tracker.Update(mat, out bound))
{
result = bound;
}
}
bound = result;
}
我知道有一些逻辑缺陷,但我仍然无法设法在不同的尝试中得到任何结果。
谢谢!
原来,真的很简单
首先定义一个你想要的类型的跟踪器。
示例:
Emgu.CV.Tracking.TrackerCSRT Tracker= new Emgu.CV.Tracking.TrackerCSRT();
然后在扫描选定区域(RoI)之前,您需要初始化跟踪器
示例:
Tracker.Initimage, roi);
重要提示:图像必须是 Emgu.CV.Mat 类型,roi Drawing.Rectangle。
要将 Bitmap 转换为 Mat,您可以使用以下方法:
示例:
public Emgu.CV.Mat toMat(Bitmap pic)
{
Bitmap bitmap=pic;
Emgu.CV.Image<Bgr, Byte> imageCV = new Emgu.CV.Image<Bgr, byte>(bitmap);
Emgu.CV.Mat mat = imageCV.Mat;
return mat;
}
注意:此代码属于 Whosebug 中的其他人,我忘记了来源。感谢 him/her.
最后使用以下语句将 returns 包围跟踪对象的矩形。技巧是对象没有 return 矩形作为方法输出,它 return 通过 out 语句。
tracker.Update(image, out roi);
最后说明:如果有人知道如何提高性能或多线程这种方法,请发表评论。
祝你有愉快的一天!
正在寻找示例代码以了解如何实施 EmguCV 跟踪器。我在这个写得不好的代码中尝试了一些东西:
class ObjectTracker
{
Emgu.CV.Tracking.TrackerCSRT tracker = new Emgu.CV.Tracking.TrackerCSRT();
bool isActive = false;
public bool trackerActive = false;
public void Track(Bitmap pic, Rectangle selection,out Rectangle bound)
{
Rectangle result = new Rectangle();
Bitmap bitmap=pic; //This is your bitmap
Emgu.CV.Image<Bgr, Byte> imageCV = new Emgu.CV.Image<Bgr, byte>(bitmap); //Image Class from Emgu.CV
Emgu.CV.Mat mat = imageCV.Mat; //This is your Image converted to Mat
if (tracker.Init(mat,selection))
{
while (tracker.Update(mat, out bound))
{
result = bound;
}
}
bound = result;
}
我知道有一些逻辑缺陷,但我仍然无法设法在不同的尝试中得到任何结果。
谢谢!
原来,真的很简单
首先定义一个你想要的类型的跟踪器。
示例:
Emgu.CV.Tracking.TrackerCSRT Tracker= new Emgu.CV.Tracking.TrackerCSRT();
然后在扫描选定区域(RoI)之前,您需要初始化跟踪器
示例:
Tracker.Initimage, roi);
重要提示:图像必须是 Emgu.CV.Mat 类型,roi Drawing.Rectangle。 要将 Bitmap 转换为 Mat,您可以使用以下方法:
示例:
public Emgu.CV.Mat toMat(Bitmap pic)
{
Bitmap bitmap=pic;
Emgu.CV.Image<Bgr, Byte> imageCV = new Emgu.CV.Image<Bgr, byte>(bitmap);
Emgu.CV.Mat mat = imageCV.Mat;
return mat;
}
注意:此代码属于 Whosebug 中的其他人,我忘记了来源。感谢 him/her.
最后使用以下语句将 returns 包围跟踪对象的矩形。技巧是对象没有 return 矩形作为方法输出,它 return 通过 out 语句。
tracker.Update(image, out roi);
最后说明:如果有人知道如何提高性能或多线程这种方法,请发表评论。
祝你有愉快的一天!