Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV Error: Assertion failed

Hi, I am trying to insert two images in one window to visualize and extract ORB features accordingly. This is the error I get when I run the program:

OpenCV Error: Assertion failed (key_ != -1 && "Can't fetch data from terminated TLS container.") in getData, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/system.cpp, line 1532
terminate called after throwing an instance of 'cv::Exception'
  what():  /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/system.cpp:1532: error: (-215) key_ != -1 && "Can't fetch data from terminated TLS container." in function getData

Aborted (core dumped)

This is also a piece of my code written in c++:

void FrameDrawer::DrawFrame(Mat &img_1, int f_k, Mat &img_2, int f_k_plus_1 , float mT)
{   
    const string &frameWinName = "ORB_VISLAM | Frames";
    namedWindow(frameWinName);

    if (img_1.empty())
    {
        cout << "img_1 empty! => BLANK!" << endl;
        img_1 = Mat::zeros(img_2.rows,img_2.cols, CV_8UC3);
    }
    if (img_2.empty())
    {
        cout << "img_2 empty! => STOP!" << endl;
        //img_1 = Mat::zeros(img_2.rows,img_2.cols, CV_8UC3);
        exit(EXIT_FAILURE);
    }

    if (f_k == f_k_plus_1)
    {
        return;
    }   
    float scale = .4;
    // img1:
    int w1,h1;
    int w1_scaled, h1_scaled;
    w1 = img_1.cols;
    h1 = img_1.rows;

    w1_scaled = w1*scale;
    h1_scaled = h1*scale;

    // img2:
    int w2,h2;
    int w2_scaled, h2_scaled;
    w2 = img_2.cols;
    h2 = img_2.rows;

    w2_scaled = w2*scale;
    h2_scaled = h2*scale;

    // MULTIPLE WINDOW:
    Mat window_img = Mat::zeros(cv::Size(w1_scaled+w2_scaled, h1_scaled), CV_8UC3);

    Mat temp1;
    Mat temp2;
    vector<cv::KeyPoint> vIniKeys; // Initialization: KeyPoints in reference frame
    vector<int> vMatches; // Initialization: correspondeces with reference keypoints

    vector<cv::KeyPoint> vCurrentKeys; // KeyPoints in current frame
    vector<bool> vbVO, vbMap; // Tracked MapPoints in current frame
    int state; // Tracking state

    //Copy variables within scoped mutex
    {
        unique_lock<mutex> lock(mMutex);
        state = mState;

        if(mState==Tracking::SYSTEM_NOT_READY)
        {
            mState=Tracking::NO_IMAGES_YET;
        }    

        if(mState==Tracking::NOT_INITIALIZED)
        {
            vCurrentKeys = mvCurrentKeys;
            vIniKeys = mvIniKeys;
            vMatches = mvIniMatches;
        }
        else if(mState==Tracking::OK)
        {
            vCurrentKeys = mvCurrentKeys;
            vbVO = mvbVO;
            vbMap = mvbMap;
        }
        else if(mState==Tracking::LOST)
        {
            vCurrentKeys = mvCurrentKeys;
        }
    } // destroy scoped mutex -> release mutex

    if(img_1.channels()<3) //this should be always true
    {
        cvtColor(img_1,img_1,CV_GRAY2BGR);
    }

    if(img_2.channels()<3) //this should be always true
    {
        cvtColor(img_2,img_2,CV_GRAY2BGR);
    }
    //Draw
    if(state==Tracking::NOT_INITIALIZED) //INITIALIZING
    {
        Point2f p_i1(1000,100);
        cv::circle(img_1,p_i1,20,Scalar(0,10,255),LINE_4);
        stringstream s_i1;
        //cout << "idx = " << f_idx<< endl;
        s_i1 << "Reference Frame = "+to_string(f_k);

        cv::putText(img_1,s_i1.str(),cv::Point(80,50),
                    cv::FONT_HERSHEY_PLAIN, 3, Scalar::all(255),4,LINE_4);
        // current keyP on img_2:
        Point2f p_i2(1000,500);
        cv::circle(img_2,p_i2,20,Scalar::all(255),LINE_4);
        stringstream s_i2;
        //cout << "idx = " << f_idx<< endl;
        s_i2 << "Current Frame = "+to_string(f_k_plus_1);

        cv::putText(img_2,s_i2.str(),cv::Point(80,50),
                    cv::FONT_HERSHEY_PLAIN, 3, Scalar::all(255),4,LINE_4);
        for(unsigned int i = 0; i < vMatches.size(); i++)
        {
            if(vMatches[i] >= 0)
            {
                //cv::line(im,vIniKeys[i].pt,vCurrentKeys[vMatches[i]].pt, Scalar(0,250,250));
                cv::circle(img_1,vIniKeys[i].pt,6,Scalar::all(255),LINE_4);
                //cv::circle(im,vCurrentKeys[vMatches[i]].pt,4,Scalar(170,1,1),LINE_4);
                cv::circle(img_2,vCurrentKeys[i].pt,6,Scalar(1,200,197),LINE_4);
            }
        }
    }
    else if(state==Tracking::OK) //TRACKING
    {
        // img_1:
        stringstream s_i1;
        s_i1 << "VISION AVAILABLE!...";

        cv::putText(img_1,s_i1.str(),cv::Point(80,50),
                    cv::FONT_HERSHEY_PLAIN, 3, Scalar(0,230,0),1,LINE_4);

        // img_2:
        stringstream s_i2;
        s_i2 << "Matching ORB features...";

        cv::putText(img_2,s_i2.str(),cv::Point(80,50),
                    cv::FONT_HERSHEY_PLAIN, 3, Scalar(0,230,0),1,LINE_4);

        mnTracked=0;
        mnTrackedVO=0;
        const float r = 5;
        const int n = vCurrentKeys.size();
        for(int i = 0; i < n; i++)
        {
            if(vbVO[i] || vbMap[i])
            {
                Point2f pt1,pt2;

                pt1.x = vCurrentKeys[i].pt.x-r;
                pt1.y = vCurrentKeys[i].pt.y-r;
                pt2.x = vCurrentKeys[i].pt.x+r;
                pt2.y = vCurrentKeys[i].pt.y+r;
                // This is a match to a MapPoint in the map
                if(vbMap[i])
                {
            //BGR color values (3 parameters)
                    cv::rectangle(img_2,pt1,pt2,Scalar(0,255,0));
                    cv::circle(img_2,vCurrentKeys[i].pt,2,Scalar(0,255,0),-1);
                    cv::line(window_img,vIniKeys[i].pt,vCurrentKeys[i].pt,Scalar(0,250,250));

                    mnTracked++;
                }
                else
                {
                    cv::rectangle(img_2,pt1,pt2,Scalar(255,0,0));
                    cv::circle(img_2,vCurrentKeys[i].pt,2,Scalar(1,0,250),-1);
                    mnTrackedVO++;
                }
            }
        }
    }
    resize(img_1,temp1, Size(w1_scaled, h1_scaled));
    temp1.copyTo(window_img(Rect(0, 0, w1_scaled, h1_scaled)));

    resize(img_2,temp2, Size(w2_scaled, h2_scaled));
    temp2.copyTo(window_img(Rect(w1_scaled, 0, w2_scaled, h2_scaled)));

    imshow(frameWinName,window_img);
    waitKey(mT);
    //waitKey();

}

Your help is appreciated! Cheers,

click to hide/show revision 2
retagged

updated 2019-03-04 02:20:55 -0600

berak gravatar image

OpenCV Error: Assertion failed

Hi, I am trying to insert two images in one window to visualize and extract ORB features accordingly. This is the error I get when I run the program:

OpenCV Error: Assertion failed (key_ != -1 && "Can't fetch data from terminated TLS container.") in getData, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/system.cpp, line 1532
terminate called after throwing an instance of 'cv::Exception'
  what():  /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/system.cpp:1532: error: (-215) key_ != -1 && "Can't fetch data from terminated TLS container." in function getData

Aborted (core dumped)

This is also a piece of my code written in c++:

void FrameDrawer::DrawFrame(Mat &img_1, int f_k, Mat &img_2, int f_k_plus_1 , float mT)
{   
    const string &frameWinName = "ORB_VISLAM | Frames";
    namedWindow(frameWinName);

    if (img_1.empty())
    {
        cout << "img_1 empty! => BLANK!" << endl;
        img_1 = Mat::zeros(img_2.rows,img_2.cols, CV_8UC3);
    }
    if (img_2.empty())
    {
        cout << "img_2 empty! => STOP!" << endl;
        //img_1 = Mat::zeros(img_2.rows,img_2.cols, CV_8UC3);
        exit(EXIT_FAILURE);
    }

    if (f_k == f_k_plus_1)
    {
        return;
    }   
    float scale = .4;
    // img1:
    int w1,h1;
    int w1_scaled, h1_scaled;
    w1 = img_1.cols;
    h1 = img_1.rows;

    w1_scaled = w1*scale;
    h1_scaled = h1*scale;

    // img2:
    int w2,h2;
    int w2_scaled, h2_scaled;
    w2 = img_2.cols;
    h2 = img_2.rows;

    w2_scaled = w2*scale;
    h2_scaled = h2*scale;

    // MULTIPLE WINDOW:
    Mat window_img = Mat::zeros(cv::Size(w1_scaled+w2_scaled, h1_scaled), CV_8UC3);

    Mat temp1;
    Mat temp2;
    vector<cv::KeyPoint> vIniKeys; // Initialization: KeyPoints in reference frame
    vector<int> vMatches; // Initialization: correspondeces with reference keypoints

    vector<cv::KeyPoint> vCurrentKeys; // KeyPoints in current frame
    vector<bool> vbVO, vbMap; // Tracked MapPoints in current frame
    int state; // Tracking state

    //Copy variables within scoped mutex
    {
        unique_lock<mutex> lock(mMutex);
        state = mState;

        if(mState==Tracking::SYSTEM_NOT_READY)
        {
            mState=Tracking::NO_IMAGES_YET;
        }    

        if(mState==Tracking::NOT_INITIALIZED)
        {
            vCurrentKeys = mvCurrentKeys;
            vIniKeys = mvIniKeys;
            vMatches = mvIniMatches;
        }
        else if(mState==Tracking::OK)
        {
            vCurrentKeys = mvCurrentKeys;
            vbVO = mvbVO;
            vbMap = mvbMap;
        }
        else if(mState==Tracking::LOST)
        {
            vCurrentKeys = mvCurrentKeys;
        }
    } // destroy scoped mutex -> release mutex

    if(img_1.channels()<3) //this should be always true
    {
        cvtColor(img_1,img_1,CV_GRAY2BGR);
    }

    if(img_2.channels()<3) //this should be always true
    {
        cvtColor(img_2,img_2,CV_GRAY2BGR);
    }
    //Draw
    if(state==Tracking::NOT_INITIALIZED) //INITIALIZING
    {
        Point2f p_i1(1000,100);
        cv::circle(img_1,p_i1,20,Scalar(0,10,255),LINE_4);
        stringstream s_i1;
        //cout << "idx = " << f_idx<< endl;
        s_i1 << "Reference Frame = "+to_string(f_k);

        cv::putText(img_1,s_i1.str(),cv::Point(80,50),
                    cv::FONT_HERSHEY_PLAIN, 3, Scalar::all(255),4,LINE_4);
        // current keyP on img_2:
        Point2f p_i2(1000,500);
        cv::circle(img_2,p_i2,20,Scalar::all(255),LINE_4);
        stringstream s_i2;
        //cout << "idx = " << f_idx<< endl;
        s_i2 << "Current Frame = "+to_string(f_k_plus_1);

        cv::putText(img_2,s_i2.str(),cv::Point(80,50),
                    cv::FONT_HERSHEY_PLAIN, 3, Scalar::all(255),4,LINE_4);
        for(unsigned int i = 0; i < vMatches.size(); i++)
        {
            if(vMatches[i] >= 0)
            {
                //cv::line(im,vIniKeys[i].pt,vCurrentKeys[vMatches[i]].pt, Scalar(0,250,250));
                cv::circle(img_1,vIniKeys[i].pt,6,Scalar::all(255),LINE_4);
                //cv::circle(im,vCurrentKeys[vMatches[i]].pt,4,Scalar(170,1,1),LINE_4);
                cv::circle(img_2,vCurrentKeys[i].pt,6,Scalar(1,200,197),LINE_4);
            }
        }
    }
    else if(state==Tracking::OK) //TRACKING
    {
        // img_1:
        stringstream s_i1;
        s_i1 << "VISION AVAILABLE!...";

        cv::putText(img_1,s_i1.str(),cv::Point(80,50),
                    cv::FONT_HERSHEY_PLAIN, 3, Scalar(0,230,0),1,LINE_4);

        // img_2:
        stringstream s_i2;
        s_i2 << "Matching ORB features...";

        cv::putText(img_2,s_i2.str(),cv::Point(80,50),
                    cv::FONT_HERSHEY_PLAIN, 3, Scalar(0,230,0),1,LINE_4);

        mnTracked=0;
        mnTrackedVO=0;
        const float r = 5;
        const int n = vCurrentKeys.size();
        for(int i = 0; i < n; i++)
        {
            if(vbVO[i] || vbMap[i])
            {
                Point2f pt1,pt2;

                pt1.x = vCurrentKeys[i].pt.x-r;
                pt1.y = vCurrentKeys[i].pt.y-r;
                pt2.x = vCurrentKeys[i].pt.x+r;
                pt2.y = vCurrentKeys[i].pt.y+r;
                // This is a match to a MapPoint in the map
                if(vbMap[i])
                {
            //BGR color values (3 parameters)
                    cv::rectangle(img_2,pt1,pt2,Scalar(0,255,0));
                    cv::circle(img_2,vCurrentKeys[i].pt,2,Scalar(0,255,0),-1);
                    cv::line(window_img,vIniKeys[i].pt,vCurrentKeys[i].pt,Scalar(0,250,250));

                    mnTracked++;
                }
                else
                {
                    cv::rectangle(img_2,pt1,pt2,Scalar(255,0,0));
                    cv::circle(img_2,vCurrentKeys[i].pt,2,Scalar(1,0,250),-1);
                    mnTrackedVO++;
                }
            }
        }
    }
    resize(img_1,temp1, Size(w1_scaled, h1_scaled));
    temp1.copyTo(window_img(Rect(0, 0, w1_scaled, h1_scaled)));

    resize(img_2,temp2, Size(w2_scaled, h2_scaled));
    temp2.copyTo(window_img(Rect(w1_scaled, 0, w2_scaled, h2_scaled)));

    imshow(frameWinName,window_img);
    waitKey(mT);
    //waitKey();

}

Your help is appreciated! Cheers,