c++ - How to create a vector of CvSVM -
i want create std::vector
of opencv cvsvm objects. when compile code:
typedef vector<cvsvm> svm_vec; svm_vec svm_data = svm_vec();
an error occurs:
in file included 2dpca.cpp:5:0: /usr/include/c++/4.8/bits/stl_construct.h: in instantiation of ‘void std::_construct(_t1*, const _t2&) [with _t1 = cvsvm; _t2 = cvsvm]’: /usr/include/c++/4.8/bits/stl_uninitialized.h:75:53: required ‘static _forwarditerator std::__uninitialized_copy<_trivialvaluetypes>::__uninit_copy(_inputiterator, _inputiterator, _forwarditerator) [with _inputiterator = __gnu_cxx::__normal_iterator<const cvsvm*, std::vector<cvsvm> >; _forwarditerator = cvsvm*; bool _trivialvaluetypes = false]’ /usr/include/c++/4.8/bits/stl_uninitialized.h:117:41: required ‘_forwarditerator std::uninitialized_copy(_inputiterator, _inputiterator, _forwarditerator) [with _inputiterator = __gnu_cxx::__normal_iterator<const cvsvm*, std::vector<cvsvm> >; _forwarditerator = cvsvm*]’ /usr/include/c++/4.8/bits/stl_uninitialized.h:258:63: required ‘_forwarditerator std::__uninitialized_copy_a(_inputiterator, _inputiterator, _forwarditerator, std::allocator<_tp>&) [with _inputiterator = __gnu_cxx::__normal_iterator<const cvsvm*, std::vector<cvsvm> >; _forwarditerator = cvsvm*; _tp = cvsvm]’ /usr/include/c++/4.8/bits/stl_vector.h:316:32: required ‘std::vector<_tp, _alloc>::vector(const std::vector<_tp, _alloc>&) [with _tp = cvsvm; _alloc = std::allocator<cvsvm>]’ 2dpca.cpp:79:29: required here /usr/local/include/opencv2/ml/ml.hpp:553:5: error: ‘cvsvm::cvsvm(const cvsvm&)’ private cvsvm(const cvsvm&); ^ in file included /usr/include/c++/4.8/bits/stl_tempbuf.h:60:0, /usr/include/c++/4.8/bits/stl_algo.h:62, /usr/include/c++/4.8/algorithm:62, /usr/local/include/opencv2/core/core.hpp:56, 2dpca.cpp:1: /usr/include/c++/4.8/bits/stl_construct.h:83:7: error: within context ::new(static_cast<void*>(__p)) _t1(__value);
compiler: g++ 4.8 opencv ver 2.4.8
since cvsvm (aka svm) not copyable, need store pointers in vector. can use opencv smart pointer cv::ptr<> that. remember access methods of svm operator -> then.
this work around.
this solves problem.
#include <opencv2\opencv.hpp> #include <vector> using namespace std; using namespace cv; int main() { vector<ptr<svm>> svm_bank; (int = 0; < 3; ++i) { mat traindata; mat responses; /*code trainingdata , responses */ svm *new_model; new_model = new svm; new_model->train(traindata, responses); svm_bank.push_back(new_model); } (int = 0; < 3; ++i) { mat samples; mat results; svm_bank[i]->predict(samples, results); } return 0; }
Comments
Post a Comment