opencv - How to store cv::Scalar objects in a Map in c++ -
i want store randomly generated scalar values in map. following attempt gives me compile error.
rng rng(0xffffffff); std::map<scalar, int> segmentcolors; scalar randomcolortemp1 = randomcolor(rng); scalar randomcolortemp2 = randomcolor(rng); segmentcolors.insert(pair<scalar, int>(randomcolortemp1, 1)); segmentcolors.insert(pair<scalar, int>(randomcolortemp1, 1));
error report follows.
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xstddef(193): error c2678: binary '<' : no operator found takes left-hand operand of type 'const cv::scalar' (or there no acceptable conversion) 1> e:\opencv\build\include\opencv2\core\operations.hpp(3193): 'bool cv::operator <(const cv::filenodeiterator &,const cv::filenodeiterator &)' [found using argument-dependent lookup] 1> e:\opencv\build\include\opencv2\core\mat.hpp(1303): or 'cv::matexpr cv::operator <(const cv::mat &,const cv::mat &)' [found using argument-dependent lookup] 1> e:\opencv\build\include\opencv2\core\mat.hpp(1304): or 'cv::matexpr cv::operator <(const cv::mat &,double)' [found using argument-dependent lookup] 1> e:\opencv\build\include\opencv2\core\mat.hpp(1305): or 'cv::matexpr cv::operator <(double,const cv::mat &)' [found using argument-dependent lookup] 1> e:\opencv\build\include\opencv2\core\mat.hpp(1984): or 'bool cv::operator <(const cv::matconstiterator &,const cv::matconstiterator &)' [found using argument-dependent lookup] 1> while trying match argument list '(const cv::scalar, const cv::scalar)' 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xstddef(192) : while compiling class template member function 'bool std::less<_kty>::operator ()(const _ty &,const _ty &) const' 1> 1> [ 1> _kty=cv::scalar 1> , _ty=cv::scalar 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\map(228) : see reference function template instantiation 'bool std::less<_kty>::operator ()(const _ty &,const _ty &) const' being compiled 1> 1> [ 1> _kty=cv::scalar 1> , _ty=cv::scalar 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\type_traits(572) : see reference class template instantiation 'std::less<_kty>' being compiled 1> 1> [ 1> _kty=cv::scalar 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xtree(1023) : see reference class template instantiation 'std::is_empty<std::less<_kty>>' being compiled 1> 1> [ 1> _kty=cv::scalar 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\map(70) : see reference class template instantiation 'std::_tree<std::_tmap_traits<_kty,_ty,_pr,_alloc,false>>' being compiled 1> 1> [ 1> _kty=cv::scalar 1> , _ty=int 1> , _pr=std::less<cv::scalar> 1> , _alloc=std::allocator<std::pair<const cv::scalar,int>> 1> ] 1> g:\uom\level 4-s1\research project\coding tests\textextraction\textextraction\source1.cpp(288) : see reference class template instantiation 'std::map<cv::scalar,int,std::less<_kty>,std::allocator<std::pair<const _kty,_ty>>>' being compiled 1> 1> [ 1> _kty=cv::scalar 1> , _ty=int 1> ] ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
can figure out error in code or give better approach store randomly generated scalar color values in map. intention store them in map avoid duplicate color values being generated. want prevent generating similar rgb values.
update
according berak's answer tried this.
rng rng(0xffffffff); struct scalarless { bool operator()(scalar &a, scalar &b) { return a[0] < b[0]; // bogus, doubt, need *real* sorting } }; scalar randomcolortemp = randomcolor(rng); map<scalar, int, scalarless> segmentcolorsmap; segmentcolorsmap.insert((pair<scalar, int>(randomcolortemp, 2)));
if want scalar key map, need supply 'less' operator, can sort it. this:
struct scalarless { bool operator()(const scalar &a, const scalar &b) { return a[0] < b[0]; // bogus, doubt, need *real* sorting } }; map<scalar,int,scalarless> segmentcolors;
Comments
Post a Comment