opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.39k stars 5.75k forks source link

Mosse tracker SEGFAULT if used in a custom class #2546

Open rokopi-byte opened 4 years ago

rokopi-byte commented 4 years ago
System information (version)
Detailed description

Mosse tracker causes a segmentation fault with the following example. Accessing the property getDefaultName cause the segfault, only using mosse. The fact that it only occurs on ARM (Raspberry) and not in my computer (x86_64), let me think can be a bug. This example from the documentation works as expected, but as soon as I put a tracker in my class, invoking whatever method cause a segmentation fault (only in ARM). OpenCV is version 4.3.0 built from source with inference engine support (using the docker as indicated in the documentation for raspberry). Also on my computer the same version.

Steps to reproduce

main.cpp

#include <iostream>
#include "person.h"

using namespace std;

int main()
{
    cout << "Hello";
    person p;
    p.createTracker("mosse");
    if (p.tracker){
        cout << "not null" << endl;
    }
    else {
        cout << "null" << endl;
    }
    cout << p.tracker->getDefaultName();
    return 0;
}

person.h

#ifndef PERSON_H
#define PERSON_H

#include <opencv2/core/core.hpp>
#include <opencv2/tracking/tracker.hpp>

class person
{
public:
    person();
    cv::Ptr<cv::Tracker> tracker;

    void createTracker(std::string type);

};

#endif // PERSON_H

person.cpp

#include "person.h"

person::person()
{
}

void person::createTracker(std::string type)
{

    if(type== "mosse") {
        tracker = cv::TrackerMOSSE::create();
    } else if(type == "csrt")
        tracker = cv::TrackerCSRT::create();
    else if(type == "kcf")
        tracker = cv::TrackerKCF::create();
    else if(type == "tld")
        tracker = cv::TrackerTLD::create();
    else {
        std::cout << "Tracking type not specified! This should not happen.";
    }

GDB

[Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1". [New Thread 0xb34a1250 (LWP 10220)] Hello not null

Thread 1 "testTrackerSF" received signal SIGSEGV, Segmentation fault. 0x00010ff0 in main () at main.cpp:21 21 cout << p.tracker->getDefaultName(); (gdb) bt

0 0x00010ff0 in main() () at main.cpp:21

Issue submission checklist
rokopi-byte commented 4 years ago

Hi, I run other tests and problem seems only related to "mosse", but also present in version 4.1.0. Any confirmation on this ?

rokopi-byte commented 4 years ago

New test: OpenCV 3.4.10 works as expected