opencv中的长错误

Posted

技术标签:

【中文标题】opencv中的长错误【英文标题】:long errors in opencv 【发布时间】:2021-10-29 00:29:15 【问题描述】:

我有一个带有opencv的C++程序如下:

#include<stdio.h>
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include</usr/local/include/opencv4/opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()

Mat image=imread("/home/c++/edge detection/DisplayImage.JPG",1);
//imshow("DisplayImage",image);
return 0;

我的 CMakeLists.txt 是

cmake_minimum_required(VERSION 3.5)
project(openCVTest)
# cmake needs this line
cmake_minimum_required(VERSION 3.1)

# Define project name
project(opencv)

# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: $OpenCV_VERSION")
message(STATUS "    libraries: $OpenCV_LIBS")
message(STATUS "    include path: $OpenCV_INCLUDE_DIRS")

if(CMAKE_VERSION VERSION_LESS "2.8.11")
    # Add OpenCV headers location to your include paths
    include_directories($OpenCV_INCLUDE_DIRS)
endif()

# Declare the executable target built from your sources
add_executable(opencv opencv.cpp)

# Link your application with OpenCV libraries
target_link_libraries(opencv $OpenCV_LIBS)

当我在我的 Ubuntu 16 终端中运行我的程序时,我得到了too many errors。这个错误太长了所以我在git中上传。

我不知道为什么会出现这么多错误,也不知道原因。我是opencv的新手,所以请对我放轻松。

提前感谢您的帮助:)

编辑:更新了 git 中的文件。

我安装了 libopencv-dev

sudo apt install libopencv-dev

我的 pkg-config opencv --libs 输出是:

$pkg-config opencv --libs
/usr/lib/i386-linux-gnu/libopencv_calib3d.so -lopencv_calib3d /usr/lib/i386-linux-gnu/libopencv_contrib.so -lopencv_contrib /usr/lib/i386-linux-gnu/libopencv_core.so -lopencv_core /usr/lib/i386-linux-gnu/libopencv_features2d.so -lopencv_features2d /usr/lib/i386-linux-gnu/libopencv_flann.so -lopencv_flann /usr/lib/i386-linux-gnu/libopencv_gpu.so -lopencv_gpu /usr/lib/i386-linux-gnu/libopencv_highgui.so -lopencv_highgui /usr/lib/i386-linux-gnu/libopencv_imgproc.so -lopencv_imgproc /usr/lib/i386-linux-gnu/libopencv_legacy.so -lopencv_legacy /usr/lib/i386-linux-gnu/libopencv_ml.so -lopencv_ml /usr/lib/i386-linux-gnu/libopencv_objdetect.so -lopencv_objdetect /usr/lib/i386-linux-gnu/libopencv_ocl.so -lopencv_ocl /usr/lib/i386-linux-gnu/libopencv_photo.so -lopencv_photo /usr/lib/i386-linux-gnu/libopencv_stitching.so -lopencv_stitching /usr/lib/i386-linux-gnu/libopencv_superres.so -lopencv_superres /usr/lib/i386-linux-gnu/libopencv_ts.so -lopencv_ts /usr/lib/i386-linux-gnu/libopencv_video.so -lopencv_video /usr/lib/i386-linux-gnu/libopencv_videostab.so -lopencv_videostab

当我运行这么简单的程序时,为什么会出现这么多错误?请任何人帮助我

【问题讨论】:

从解决第一个问题开始:'error "OpenCV 4.x+ requires enabled C++11 support"' 通过弄清楚如何启用 C++11 支持。 首先尝试指定您的目标语言:project(DisplayImage LANGUAGES CXX). 确定您使用的是 C++11 或更高版本的编译器吗? /usr/include/opencv2/core/cvdef.h:740:4: error: #error "OpenCV 4.x+ requires enabled C++11 support" 提示:当出现多个错误时,专注于最先出现的错误,忽略后面的一切。 你的编译器太旧了。找出你的编译器的版本。 【参考方案1】:

您发布的错误:

错误“OpenCV 4.x+ 需要启用 C++11 支持”

这意味着您需要构建代码并“告诉编译器”使用 c++11

你可以在 cmake 中设置标志:

set (CMAKE_CXX_STANDARD 11)

此标志仅在 3.1 后可用

https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html

【讨论】:

我做了这些改变。并给cmake . 仍然出现错误。请检查我的编辑

以上是关于opencv中的长错误的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu上opencv中的错误/usr/include/opencv2/nonfree/features2d.hpp错误向量

用于 IP 摄像机访问的 OpenCV 2.4.11 中的 opencv_ffmpeg**.dll 错误?

OpenCV 2.x 中的像素访问错误

opencv中的acos函数错误

OpenCV 库中的错误 - 2.4.9

opencv:wasm 中的匹配错误