最新版本的 OpenCV(4) 沒有用于創建 HAAR CASCADE 檔案的 createsamples 功能。這只是令人難以置信。要獲得此功能,有兩種解決方案:1) 在另一臺機器上下載舊版本或 2) 編譯 createsamples.cpp 我選擇第二項,因為任何人都可以隨時適應 kluge。第 2 項帶有許多看起來相同的錯誤,如下所示:
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
許多錯誤來自 core.hpp 和 createsample.cpp。createsample.cpp 在這里:https : //github.com/opencv/opencv/blob/master/apps/createsamples/createsamples.cpp
和 core.hpp 在這里:https : //github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core.hpp
非常感謝有關修復這些錯誤的任何見解。
uj5u.com熱心網友回復:
最簡單的方法似乎是下載較舊的 opencv 版本源代碼,如https://github.com/opencv/opencv/archive/2.4.13.6.zip并將其解壓縮到任何位置。在該檔案夾中執行
mkdir build
cd build
cmake ..
make
cd bin
在那里你會找到的二進制檔案opencv_createsamples,opencv_traincascade等等。
沒有必要安裝那個舊版本(如果你使用 'make install' 會發生這種情況),只需使用當前安裝的任何版本的 opencv 構建來完成所有任務,如果您需要創建示例或訓練級聯,請使用此構建在您將其復制到的目錄中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/355880.html
