Home > Mobile >  OpenCV createsamples.cpp debugging
OpenCV createsamples.cpp debugging

Time:11-11

The newest version of OpenCV(4) does not come with createsamples feature for creating HAAR CASCADE files. It's just mind boggling. To attain this feature, there are two solutions: 1) Download an older version on a different machine or 2) Compile createsamples.cpp I am choosing item two as anyone can settle for kluge anytime. Item two comes with many errors that look the same as shown below:

 harry@harry-usedmachine:/usr/include/opencv4$ sudo g   createsamples.cpp 
[sudo] password for harry:        
In file included from createsamples.cpp:48:
/usr/include/opencv4/opencv2/core.hpp:2523:16: error: ‘FileStorage’ has not been declared
 2523 |     void write(FileStorage& fs) const;
      |                ^~~~~~~~~~~
/usr/include/opencv4/opencv2/core.hpp:2573:15: error: ‘FileStorage’ has not been declared
 2573 |     void save(FileStorage& fs) const;
      |               ^~~~~~~~~~~
/usr/include/opencv4/opencv2/core.hpp:2577:21: error: ‘FileStorage’ does not name a type
 2577 |     void load(const FileStorage& node);
      |                     ^~~~~~~~~~~
/usr/include/opencv4/opencv2/core.hpp:3088:24: error: ‘FileStorage’ has not been declared
 3088 |     virtual void write(FileStorage& fs) const { CV_UNUSED(fs); }
      |                        ^~~~~~~~~~~
/usr/include/opencv4/opencv2/core.hpp:3093:34: error: ‘FileStorage’ was not declared in this scope
 3093 |     CV_WRAP void write(const Ptr<FileStorage>& fs, const String& name = String()) const;
      |                                  ^~~~~~~~~~~
/usr/include/opencv4/opencv2/core.hpp:3093:45: error: template argument 1 is invalid
 3093 |     CV_WRAP void write(const Ptr<FileStorage>& fs, const String& name = String()) const;
      |                                             ^
/usr/include/opencv4/opencv2/core.hpp:3172:22: error: ‘FileStorage’ has not been declared
 3172 |     void writeFormat(FileStorage& fs) const;
      |                      ^~~~~~~~~~~
/usr/include/opencv4/opencv2/core.hpp: In static member function ‘static cv::Ptr<_Tp> cv::Algorithm::load(const String&, const String&)’:
/usr/include/opencv4/opencv2/core.hpp:3135:9: error: ‘FileStorage’ was not declared in this scope
 3135 |         FileStorage fs(filename, FileStorage::READ);
      |         ^~~~~~~~~~~
In file included from /usr/include/opencv4/opencv2/core.hpp:55,
                 from createsamples.cpp:48:
/usr/include/opencv4/opencv2/core.hpp:3136:19: error: ‘fs’ was not declared in this scope; did you mean ‘ffs’?
 3136 |         CV_Assert(fs.isOpened());
      |                   ^~
/usr/include/opencv4/opencv2/core/base.hpp:342:38: note: in definition of macro ‘CV_Assert’
  342 | #define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0)
      |                                      ^~~~
In file included from createsamples.cpp:48:
/usr/include/opencv4/opencv2/core.hpp:3137:41: error: ‘fs’ was not declared in this scope; did you mean ‘ffs’?
 3137 |         FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
      |                                         ^~
      |                                         ffs
/usr/include/opencv4/opencv2/core.hpp:3137:18: error: ‘fn’ has incomplete type
 3137 |         FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
      |                  ^~
In file included from /usr/include/opencv4/opencv2/core/base.hpp:58,
                 from /usr/include/opencv4/opencv2/core.hpp:55,
                 from createsamples.cpp:48:
/usr/include/opencv4/opencv2/core/cvstd.hpp:150:18: note: forward declaration of ‘class cv::FileNode’
  150 | class CV_EXPORTS FileNode; //for string constructor from FileNode
      |                  ^~~~~~~~
In file included from createsamples.cpp:48:
/usr/include/opencv4/opencv2/core.hpp: In static member function ‘static cv::Ptr<_Tp> cv::Algorithm::loadFromString(const String&, const String&)’:
/usr/include/opencv4/opencv2/core.hpp:3156:9: error: ‘FileStorage’ was not declared in this scope
 3156 |         FileStorage fs(strModel, FileStorage::READ   FileStorage::MEMORY);
      |         ^~~~~~~~~~~
/usr/include/opencv4/opencv2/core.hpp:3157:41: error: ‘fs’ was not declared in this scope; did you mean ‘ffs’?
 3157 |         FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname];
      |                                         ^~
      |                                         ffs

Many of the errors are coming from core.hpp and createsample.cpp. createsample.cpp is here: https://github.com/opencv/opencv/blob/master/apps/createsamples/createsamples.cpp

and core.hpp is here: https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core.hpp

Would much appreciate any insights on fixing these errors.

CodePudding user response:

Easiest way seems to be downloading an older opencv version source code like https://github.com/opencv/opencv/archive/2.4.13.6.zip and extract it to any location. In that folder perform

mkdir build
cd build
cmake ..
make
cd bin

there you will find the binaries of opencv_createsamples, opencv_traincascade etc.

It is NOT necessary to install that old version (that would happen if you use 'make install' ), just use your currently installed opencv build of any version for all tasks and if you need to create sample or train a cascade, use this build at the directory where you copy it to.

  • Related