我试图用C++编写一个代码,在可视化代码工作室(ubuntu)中使用Opencv。
我在下一篇教程之后编写了opencv:http://www.codebind.com/cpp-tutorial/install-opencv-ubuntu-cpp/
我想使用,但我无法使它工作。
我的cpp代码如下:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
// using namespace cv;
// using namespace std;
int main(int argc, char const *argv[])
{
std::cout << "Hello World\n";
cv::Mat image;
image = cv::imread("image.jpg"); // Read the file
// namedWindow("show image",WINDOW_AUTOSIZE);
//imshow("show image", image);
std::cin.get();
return 0;
}我的c_cpp_propierties.json文件是下一个:
{
"configurations": [
{
"name": "Linux",
"browse": {
"path": [
"/opt/opencv/include/opencv",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"/opt/opencv/include/opencv",
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}json的任务是
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g", "canny.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}当我编译代码时,我会收到以下输出:
执行任务: g++ -g canny.cpp <
/tmp/cc01zEdA.o:函数main': /home/beaa/Estudio/CPP/basicOpenCV/canny.cpp:13: undefined reference tocv::imread(cv::String &,/tmp/cc01zEdA.o:函数cv::String::String(char const*)': /usr/local/include/opencv2/core/cvstd.hpp:597: undefined reference tocv::cv::Mat::~Mat()': /usr/local/include/opencv2/core/mat.inl.hpp:682: undefined reference tocv::cv::Mat::~Mat()': /usr/local/include/opencv2/core/mat.inl.hpp:682: undefined reference tocv::cv::Mat::release()': /usr/local/include/opencv2/core/mat.inl.hpp:794: undefined reference to(Tmp) /tmp/cc01zEdA.o: In function cv::Mat::operator=(cv::Mat&&)': /usr/local/include/opencv2/core/mat.inl.hpp:1357: undefined reference tocv::error(void*) collect2: collect2返回1出口状况El proceso del终端finalizócon el código de salida: 1
如你所见,我用gcc做编译器。
我想opencv路径是找不到的,但我尝试过修复它,但我无法。
提前感谢
发布于 2018-05-30 20:56:42
用ubuntu编译opencv代码实际上非常简单。您可以使用此链接来完成此操作。http://answers.opencv.org/question/25642/how-to-compile-basic-opencv-program-in-c-in-ubuntu/
您需要下载opencv文件并将其解压缩到某个位置,编写cpp代码,在命令行运行时只需给opencv包含和lib路径。
如果在ubuntu中使用visual studio并不是必须的,则可以使用所描述的过程。
https://stackoverflow.com/questions/50586405
复制相似问题