【问题标题】:How to compile project c++ with opencv on g++ ?如何在 g++ 上使用 opencv 编译项目 c++?
【发布时间】:2017-10-10 06:55:00
【问题描述】:

我使用ubuntu 14.04opencvC++ 我想运行这个项目: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)));
                                                         ^

有什么问题以及如何编译这个项目?

【问题讨论】:

  • 您自己构建了 OpenCV 库,还是只是下载了预编译的库?在后一种情况下,ml 模块可能尚未包含在您的库中。如果是这种情况,您需要自己构建您的 OpenCV 库。
  • 究竟应该怎么做? ?我是怎么做到的?
  • 在继续之前,首先检查 ml 模块是否真的不包含在您的 OpenCV 中,因为自己构建 OpenCV 可能是一项耗时的工作。尝试#include &lt;opencv2/ml.hpp&gt;,如果找不到标头,那么您应该尝试按照this 指南构建您的OpenCV。
  • 'c.cpp:1:26: 致命错误:opencv2/ml.hpp: 没有这样的文件或目录'
  • @devnglee thnx 获取此链接:docs.opencv.org/2.4/doc/tutorials/introduction/windows_install/… 但我有 Ubuntu

标签: c++ opencv svm


【解决方案1】:

cv::ml has not been declared 提示你没有正确配置openCV,错误:'to_string' is not a member of 'std' 可能是libstdc++过时引起的,尝试用-std=c编译++11 标志

【讨论】:

  • 那我该怎么办?
  • 尝试使用 -std=c++11 标志进行编译 - 这是针对 to_string() 错误,对于 opencv 错误,请检查您的包含,因为编译器无法找到 cv::ml(you可以尝试将带有 opencv 路径的 -I 标志添加到 g++ 编译选项中)
  • 请给我命令,我该怎么办?举个例子
  • g++ -std=c+11 -I/path_to_opencv/include -o l RealtimeDigitClassifier.cpp pkg-config --cflags --libs opencv
  • 同样的问题!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-13
  • 2022-01-09
  • 2014-09-12
  • 2017-06-14
相关资源
最近更新 更多