error C2248: 'CvSVM::CvSVM' : cannot access private member declared in class 'CvSVM' [closed]

asked 2015-01-26 23:05:05 -0600

Rajind gravatar image

updated 2015-01-27 03:24:45 -0600

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 ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-29 00:33:40.808158

Comments

Can you please state exactly where the error is raised? On what line for example?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-27 02:33:23 -0600 )edit
1
  • could you please strip down that wall of code to the relevant parts ?
  • trying to access which member gives you that error ?
  • code from 2011, hmmm...
  • 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 ?

berak gravatar imageberak ( 2015-01-27 02:39:58 -0600 )edit
1

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.

Rajind gravatar imageRajind ( 2015-01-27 02:59:48 -0600 )edit
1

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 '->'

berak gravatar imageberak ( 2015-01-27 03:37:48 -0600 )edit

Thank you very much. I'll try that. :)

Rajind gravatar imageRajind ( 2015-01-27 04:27:20 -0600 )edit

@berak --> again a function that is not in the documentation ^^ thanks for pointing it out!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-27 04:42:47 -0600 )edit

@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 gravatar imageberak ( 2015-01-27 04:52:40 -0600 )edit
1

@berak i was talking about the void glob(string dirname, vector<string> files); function. It is nowhere to be found in documentation!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-27 06:28:49 -0600 )edit
1

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:

  • map<string,ptr<cvsvm> > classes_classifiers;
  • classes_classifiers[class_]->train(samples_32f,labels);

any other suggestion? Thanks!

fmartinez gravatar imagefmartinez ( 2015-01-27 06:52:11 -0600 )edit
1

@fmartinez, you will have to intialize them with new CvSVM, like classes_classifiers["pizza"] = new CvSVM

(sorry, should have pointed that out more, i guess ;)

berak gravatar imageberak ( 2015-01-27 07:17:50 -0600 )edit