error C2248: 'CvSVM::CvSVM' : cannot access private member declared in class 'CvSVM' [closed]
I am trying to use bag of features model and train and SVM. I am using this tutorial and this sample code. I am using Windows 8 and OpenCV 2.4.10. I am running this on Visual Studio 2012. But i am continuously getting this error 'CvSVM::CvSVM' : cannot access private member declared in class 'CvSVM' I tried using OpenCV 2.4.9 but same error is still there.
I searched a lot for this and still could not find a proper solution for this. Please help me on this. Thanks in advance. Below is the code. I am using this Dirent API for Microsoft Visual Studio as well.
EDIT: Lines 146 gives the error. classes_classifiers[class_].train(samples_32f,labels);
This is complete output from visual studio when compiling the main.cpp.
------ Build started: Project: ConsoleApplication1, Configuration: Debug x64 ------
1> main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\utility(138): error C2248: 'CvSVM::CvSVM' : cannot access private member declared in class 'CvSVM'
1> D:\Program Files\opencv\build\include\opencv2/ml/ml.hpp(553) : see declaration of 'CvSVM::CvSVM'
1> D:\Program Files\opencv\build\include\opencv2/ml/ml.hpp(452) : see declaration of 'CvSVM'
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\map(198) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<const std::basic_string<_Elem,_Traits,_Alloc>&,CvSVM>(_Other1,_Other2 &&,void **)' being compiled
1> with
1> [
1> _Ty1=std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
1> _Ty2=CvSVM,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>,
1> _Other1=const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,
1> _Other2=CvSVM
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\map(198) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<const std::basic_string<_Elem,_Traits,_Alloc>&,CvSVM>(_Other1,_Other2 &&,void **)' being compiled
1> with
1> [
1> _Ty1=std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
1> _Ty2=CvSVM,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>,
1> _Other1=const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,
1> _Other2=CvSVM
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\map(191) : while compiling class template member function 'CvSVM &std::map<_Kty,_Ty>::operator [](const std::basic_string<_Elem,_Traits,_Alloc> &)'
1> with
1> [
1> _Kty=std::string,
1> _Ty=CvSVM,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> main.cpp(146) : see reference to function template instantiation 'CvSVM &std::map<_Kty,_Ty>::operator [](const std::basic_string<_Elem,_Traits,_Alloc> &)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=CvSVM,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> main.cpp(123) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=CvSVM
1> ]
========== Build ...
Can you please state exactly where the error is raised? On what line for example?
opencv has a nice
void glob(string dirname, vector<string> files);
function. better use that instead of traversing dirs manually, and being dependant on os specific code for this.which opencv version are you using ?
Thank you for your comments. Lines 146 gives the error.
classes_classifiers[class_].train(samples_32f,labels);
I didn't know about `void glob(string dirname, vector<string> files); I'll look into that.
ahh, now it looks, like the copy contructor for CvSVM can't be accessed (or does not exist, see here, right ?
seems to me, that in 2.4 you can't have a
map<string,CvSVM>
(which would require such a (public)copy ctor).you probably have to change that code, so try a
map<string,Ptr<CvSVM> >
, use new to create it, and change the access from '.' to '->'Thank you very much. I'll try that. :)
@berak --> again a function that is not in the documentation ^^ thanks for pointing it out!
@StevenPuttemans, seems more to me , that it's not implemented (not so much a lack of documentation)
iirc, a lot of the older c-style ml classes just did not support copying
having a private copy ctor, probably means, that it's even forbidden to use it (and that the compiler should not auto-generate one, imho, that was the reason for adding this)
@berak i was talking about the
void glob(string dirname, vector<string> files);
function. It is nowhere to be found in documentation!Hi!. I have the same problem and I changed my code as @berak recomended. Now the code is compiling but during running appears: "segmentation fault"..."core domped"...etc.
I did this changes at code:
any other suggestion? Thanks!
@fmartinez, you will have to intialize them with
new CvSVM
, likeclasses_classifiers["pizza"] = new CvSVM
(sorry, should have pointed that out more, i guess ;)