rmsalinas / DBow3

Improved version of DBow2
Other
507 stars 238 forks source link

bug in "void DescManip::fromString(cv::Mat &a, const std::string &s)" #6

Open kokerf opened 7 years ago

kokerf commented 7 years ago

Hi! When I run the demo, demo_genera, there was an error occurred show as follow:

... Done Creating a small database... OpenCV Error: Assertion failed (s >= 0) in setSize, file /home/koker/library/opencv/modules/core/src/matrix.cpp, line 306 /home/koker/library/opencv/modules/core/src/matrix.cpp:306: error: (-215) s >= 0 in function setSize ...

and the opencv I use was 3.1.0. I debugged the codes and found that the error was occurred in file "src/DescManip.cpp" at a.create(1, cols, type);(line 185). because there were wrong values of type and cols loading from ss.

there was my solution:

void DescManip::fromString(cv::Mat &a, const std::string &s)
{

    //check if the dbow3 is present
    string ss_aux;
    stringstream ss(s);
    ss>>ss_aus;
    if(ss_aux.find("dbw3")==std::string::npos){//is dbow2
        //READ UNTIL END
        //stringstream ss(s);
        int val;
        vector<uchar> data;data.reserve(100);
        while( ss>>val) data.push_back(val);
        //copy to a
        a.create(1,data.size(),CV_8UC1);
        memcpy(a.ptr<char>(0),&data[0],data.size());
    }
    else{
        int type,cols;
        //stringstream ss(s);
        ss >>type>>cols;
        a.create(1,  cols, type);
animetrics commented 7 years ago

This has been fixed both in my branch and in @hcjghr's (who also issued a pull request #2) branch. @rmsalinas has not made the change.

junzhang2016 commented 6 years ago

Yes! I solved the same problem with @kokerf 's solution!

But, a little mistake in the solution: ss>>ss_aus;

It should be: ss>>ss_aux;