cv2.decolor - 'std::out_of_range' - when used more than once (Bug #3945)
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
bugfix #3945 pass idx,idx1 by reference instead of static vars
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
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