cv2.decolor - 'std::out_of_range' - when used more than once (Bug #3945)


Added by Colin Honigman over 10 years ago. Updated over 10 years ago.


Status:Done Start date:2014-10-06
Priority:Normal Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:python bindings
Target version:3.0-alpha
Affected version:branch 'master' (3.0-dev) Operating System:Linux
Difficulty: HW Platform:x86
Pull request:https://github.com/Itseez/opencv/pull/3312

Description

When using the cv2.decolor method twice in a row I get an "std::out_of_range" even if it's the same image. Happens every time the method is called more than once. Testing on Linux, Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-36-generic x86_64).


Associated revisions

Revision 56fcc41d
Added by be rak over 10 years ago

bugfix #3945 pass idx,idx1 by reference instead of static vars

Revision d01ee09f
Added by Vadim Pisarevsky almost 10 years ago

Merge pull request #3945 from nisargthakkar:DocBugFix4282

History

Updated by be rak over 10 years ago

here's the culprit: (photo\src\contrast_preserve.hpp:214)

void Decolor::add_vector(vector < vector <int> > &comb, int r,int g,int b)
{
    static int idx =0;
    comb.push_back( vector <int>() );
    comb.at(idx).push_back( r );
    comb.at(idx).push_back( g );
    comb.at(idx).push_back( b );
    idx++;
}

idx stays alive for the whole lifetime of the program, and won't be reset on the next call to decolor() or for a new instance of Decolor. (so the 2nd call to decolor() will start from the last valid index, not from 0, leading to an out-of-range error)

btw, same problem for Decolor::add_to_vector_poly()


idx should be passed by (non-const) reference, instead of the static local var

https://github.com/Itseez/opencv/pull/3312

Updated by Ilya Lavrenov over 10 years ago

  • Status changed from New to Done
  • Pull request set to https://github.com/Itseez/opencv/pull/3312

Also available in: Atom PDF