在cmake里面找到OPENCV_ENABLE_ALLOCATOR_STATS或者在search里面搜索,然后把后面的勾选去掉
错误1:
CMake Warning at cmake/OpenCVDownload.cmake:202 (message):
FFMPEG: Download failed: 6;"Couldn't resolve host name"
For details please refer to the download log file:
E:/software/opencv/install/CMakeDownloadLog.txt
Call Stack (most recent call first):
3rdparty/ffmpeg/ffmpeg.cmake:20 (ocv_download)
modules/videoio/cmake/detect_ffmpeg.cmake:14 (download_win_ffmpeg)
modules/videoio/cmake/init.cmake:3 (include)
modules/videoio/cmake/init.cmake:22 (add_backend)
cmake/OpenCVModule.cmake:312 (include)
cmake/OpenCVModule.cmake:375 (_add_modules_1)
modules/CMakeLists.txt:7 (ocv_glob_modules)
解决方法
重新Configure
, 配置成功。
配置成功之后选择Generate
:
表示生成了Makefile
生成好Makefile之后,我们开始编译Opencv源代码
即可打开cmd,然后执行命令mingw32-make install
等待编译完成
编译成功之后我们只需要将opencv\build\include
,opencv\install\bin
, opencv\install\lib
目录添加到环境变量中即可
cmake_minimum_required(VERSION 3.15)
project(untitled)
set(CMAKE_CXX_STANDARD 14)
# 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
# set(OpenCV_DIR "E:\\software\\opencv\\build\\x64\\vc15\\lib")
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}")
# Add OpenCV headers location to your include paths
include_directories( ${OpenCV_INCLUDE_DIRS} )
# Declare the executable target built from your sources
add_executable(${PROJECT_NAME} main.cpp )
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS})
#include
#include
using namespace cv;
int main(int argc, char** argv )
{
Mat image;
image = imread( "C:\\Users\\oceanstar\\Pictures\\Camera Roll\\test.jpg", 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
编译运行:
> mkdir build
> cd build
> CMake -G "MinGW Makefiles" ../
> mingw32-make