我需要些帮助。我想在我的计算机(运行在Ubuntu上)上安装Opencv4,并将它与VSCode一起使用。
很多教程都解释了如何做到这一点,下面是我所遵循的其中一个:https://vitux.com/opencv_ubuntu/
接下来,我参加了我老师给我的一个检查安装的程序:
#include <iostream>
#include <string>
#include <opencv4/opencv2/highgui.hpp>
using namespace cv;
using namespace std;
int main(void)
{
string imageName("/home/baptiste/Documents/M1/infographie/images/lena.jpg"); // path to the image
Mat img;
img = imread(imageName, IMREAD_COLOR); // Read the file as a color image
if( img.empty() ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
Mat img_gray;
img_gray = imread(imageName,IMREAD_GRAYSCALE); //Read the file as a grayscale image
if( img_gray.empty() ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
imshow( "Image read", img ); // Show our color image inside the window.
imshow("Grayscale image read", img_gray); //Show our grayscale image inside the window.
waitKey(0); // Wait for a keystroke in the window
imwrite("/home/baptiste/Documents/M1/infographie/images/lena_gray.jpg", img_gray); //Save our grayscale image into the file
return 0;
}我还写了一个makefile:
CC=g++
read_image: read_image.cpp
$(CC) read_image.cpp -o read_image `pkg-config --libs --cflags opencv4`
clean:
rm -f read_image但是当我编辑的时候,我得到了这样的信息:
g++ read_image.cpp -o read_image `pkg-config --libs --cflags opencv4`
In file included from read_image.cpp:3:
/usr/local/include/opencv4/opencv2/highgui.hpp:46:10: fatal error: opencv2/core.hpp: Aucun fichier ou dossier de ce type
46 | #include "opencv2/core.hpp"
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [makefile:4 : read_image] Erreur 1我还发现了opencv安装中的一个问题:在/usr/local/include中,我有一个opencv4文件夹,其中包含.一个opencv2文件夹,然后是整个安装。
我对此的解释是:模块所包含的内容不是在好地方读的。我的程序实际上识别了highgui.hpp的位置,但是该模块不识别core.hpp的好位置。
我没有看到任何人有这个问题,所以这可能是相当奇怪,但谁能帮助我吗?
此外,我还将"/usr/local/include/opencv4/**"添加到VSCode配置中。
谢谢你的回答和时间,你将投资。
编辑1:这是我的c_cpp_properties.json:
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include/opencv4/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}我是如何创建"tasks.json“文件的?
发布于 2022-02-12 14:13:13
--我把它解释为:模块所包含的内容不是在好地方读的。我的程序实际上识别了highgui.hpp的位置,但是该模块不识别core.hpp的好位置。
好的,正确的分析,作为一个菜鸟!!
你老师的考试计划已经不正确了
#include <opencv4/opencv2/highgui.hpp>应:
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp> // added for clarity
#include <opencv2/imgcodecs.hpp> // same您可能应该从makefile中删除pkg-config部件(不透明且不受支持),手动添加路径/库,这样您至少可以“知道您在做什么”:
CC=g++
INC=/usr/local/include/opencv4
LIB=/usr/local/lib
LIBS=-lopencv_core -lopencv_highgui -lopencv_imgcodecs
read_image: read_image.cpp
$(CC) -I$(INC) read_image.cpp -o read_image -L$(LIB) $(LIBS)
clean:
rm -f read_imagehttps://stackoverflow.com/questions/71092448
复制相似问题