如何在 g++ 上使用 opencv 编译项目 c++

How to compile project c++ with opencv on g++ ?

本文关键字:opencv 编译 项目 c++ g++      更新时间:2023-10-16

ubuntu 14.04opencv用于C++我想运行这个项目:https://github.com/sharpe-developer/Realtime-Digit-Classifier如果我这样做:

 g++  -o l RealtimeDigitClassifier.cpp    `pkg-config --cflags --libs opencv`

我得到 :

In file included from HogSvm.h:19:0,
                 from RealtimeDigitClassifier.cpp:16:
Svm.h:44:23: error: ‘cv::ml’ has not been declared
     void  SetType(cv::ml::SVM::Types type) const;
                       ^
Svm.h:44:38: error: expected ‘,’ or ‘...’ before ‘type’
     void  SetType(cv::ml::SVM::Types type) const;
                                      ^
Svm.h:45:25: error: ‘cv::ml’ has not been declared
     void  SetKernel(cv::ml::SVM::KernelTypes kernel) const;
                         ^
Svm.h:45:46: error: expected ‘,’ or ‘...’ before ‘kernel’
     void  SetKernel(cv::ml::SVM::KernelTypes kernel) const;
                                              ^
Svm.h:63:13: error: ‘ml’ is not a member of ‘cv’
     cv::Ptr<cv::ml::SVM> m_svm;
             ^
Svm.h:63:13: error: ‘ml’ is not a member of ‘cv’
Svm.h:63:24: error: template argument 1 is invalid
     cv::Ptr<cv::ml::SVM> m_svm;
                        ^
RealtimeDigitClassifier.cpp: In function ‘void ProcessFrame(const HogSvm&, const HogSvm&, cv::Mat&, cv::Mat&)’:
RealtimeDigitClassifier.cpp:60:34: error: ‘>>’ should be ‘> >’ within a nested template argument list
     std::vector<std::vector<Point>> contours;
                                  ^
RealtimeDigitClassifier.cpp:99:35: error: ‘to_string’ is not a member of ‘std’
             putText(displayFrame, std::to_string(prediction), boundRect.tl() - Point(0, 5), FONT_HERSHEY_PLAIN, 1.4, Scalar(0, 0, 0));                
                                   ^
RealtimeDigitClassifier.cpp: In function ‘int main(int, char**)’:
RealtimeDigitClassifier.cpp:141:57: error: ‘CAP_PROP_FRAME_WIDTH’ was not declared in this scope
     Size vidSize = Size(static_cast<int>(vidCapture.get(CAP_PROP_FRAME_WIDTH)),
                                                         ^
RealtimeDigitClassifier.cpp:142:57: error: ‘CAP_PROP_FRAME_HEIGHT’ was not declared in this scope
                         static_cast<int>(vidCapture.get(CAP_PROP_FRAME_HEIGHT)));
                                                         ^

问题是什么以及如何编译此项目?

cv::ml 尚未声明可能表明您没有正确配置 openCV,错误:"to_string"不是 'std' 的成员可能是由过时的 libstdc++ 引起的,请尝试使用 -std=c++11 标志编译