重新初始化后,OpenCV 3 Tracker将无法使用 [英] OpenCV 3 Tracker won't work after reinitialization

查看:109
本文介绍了重新初始化后,OpenCV 3 Tracker将无法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用OpenCV 3跟踪模块进行跟踪时遇到问题.它的行为相同,无论我使用接口类(cv :: Tracker)还是带有实现的类(例如cv :: TrackerMedianFlow或cv :: TrackerMIL等).样本是来自OpenCV样本文件夹的经过修改的样本 正确创建后

I have issue using OpenCV 3 tracking module for tracking. It behaves same, either I use interface class (cv::Tracker) or class with implementation (like cv::TrackerMedianFlow or cv::TrackerMIL, etc). Sample is a bit modified sample from OpenCV sample folder After correct creation

Ptr<Tracker> tracker = Tracker::create( tracker_algorithm );
if ( tracker == NULL )
{
    std::cout << "***Error in the instantiation of the tracker...***\n";
    return -1;
}

初始化工作正常

if ( !tracker->init( frame, boundingBox ) )
{
    std::cout << "***Could not initialize tracker...***\n";
    return -1;
}

当跟踪丢失时,问题会在后期出现,并带有主循环.我使用单独的检测器来定义新目标.找到新目标后,我会清除跟踪器并使用新值对其进行初始化

Problem occurs late on, withing main loop, when tracking is lost. I use separate detector for defining new target. When I find new target, I clear tracker and initialize it with new value

                    tracker->clear( );
                    if ( !tracker->init( frame, detectedNewBBox) )
                    {
                        std::cout << "***Could not initialize tracker without history...***\n";
                        return -1;
                    }

但是,初始化总是返回false.我试图找出为什么无法初始化跟踪器? 数据检查了几次,看起来很正确.我什至进行了一个小实验,试图在创建跟踪器后立即使用相同的数据初始化跟踪器,而不会使用循环初始化它,并且效果很好. 难道我做错了什么?我找不到与此有关的任何文档... 这是与此有关的可用文档的链接: OpenCV 3跟踪器文档

However, initialization always returns false. I am trying to find out WHY tracker cannot be initialized? Data was check few time, and looks pretty correct. I even conducted small experiment, trying to initialize tracker right after creation with same data it won't initialize withing loop and it works perfect. Am I doing something wrong? I was unable to find any documentation on this... Here is link to available documentation on this: OpenCV 3 Tracker documentation

谢谢您的努力!

推荐答案

我只是遇到了同样的问题,这就是我如何使其工作的方法:

I just ran into the same problem, here's how I got it to work :

tracker->clear();

Ptr<Tracker> trackerNew = Tracker::create( tracker_algorithm );

tracker = trackerNew;
tracker->init( image, boundingBox );

可能不是正确的方法或最漂亮的方法,但它确实可以完成工作:)

Might not be the right way or the prettiest but it does the job :)

这篇关于重新初始化后,OpenCV 3 Tracker将无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆