CMake compiles opencv3.0 using Qt's own MinGW four point one four

Posted by MCrosbie on Sat, 22 Jan 2022 23:16:19 +0100

brief introduction

target

CMake compiles opencv3.0 using MinGW-7.3.0-32 provided with QtCreator 4.1. Create a new Qt project and successfully open the picture.

Fundamentals of reading

  • Understand Qt programming
  • Use of QtCreator.
  • Learn about OpenCV, OpenCV3 4.1.
  • Understand CMake.

Environmental description

Operating system: Windows-10-64bit

QT version: Qt5 12.6/QtCreator4. ten

OpenCV: 3.4.14

Cmake: V3.21

python: V3.9

Software introduction

Qt

Qt (official pronunciation [kju:t], with cut) is a cross platform C++ The development library is mainly used to develop Graphical User Interface (GUI) programs. Of course, it can also develop command-line (CUI) programs without interface.

Qt still exists Python , Ruby, Perl and other scripting languages, that is, Qt based programs can be developed using scripting languages. The open source community is like this. Good things will be derived, extended, used everywhere and grow stronger and stronger.

Qt supports many operating systems, such as general operating systems Windows, Linux, Unix and smart phone systems Android , iOS, WinPhone, embedded system QNX, VxWorks, etc.

Cmake

CMake is a cross platform automated construction system, which uses a named cmakelists Txt file to describe the construction process. CMake can run in Windows and Linux environments. According to the configured compilers, it can generate Makefile files that conform to the operating system. Under Windows, it can generate VS project file system.

Then use it according to the general construction method. This makes you familiar with a Integrated development environment (IDE) developers can build their software in a standard way. This ability to use the native construction system of each platform is the difference between CMake and other similar systems such as SCons.

Python

Python was developed by [Guido van Rossum] of the Dutch Society for mathematical and computer science research( https://baike.baidu.com/item/Guido Van Rossum / 3225314) was designed in the early 1990s as a door called ABC language A substitute for. Python provides efficient advanced data structure , but also simple and effective object-oriented Programming. Python syntax and dynamic types, and Interpretive language It has become a programming language for scripting and rapid application development on most platforms. With the continuous updating of versions and the addition of new language functions, it has gradually been used for the development of independent and large-scale projects.

Pythoninterpreter Easy to expand, can use C or C++ (or other languages that can be called through C) extend new functions and data type . Python can also be used as an extender language in customizable software. Python's rich standard library provides the source code or code applicable to various major system platforms Machine code.

OpenCV

OpenCV is based on BSD Cross platform for licensed (open source) distribution computer vision and machine learning Software library, which can run in Linux,Windows,Android And [Mac OS]( https://baike.baidu.com/item/Mac OS / 2840867). It is lightweight and efficient - it is composed of a series of C functions and a small number of C + + classes. At the same time, it provides interfaces with Python, Ruby, MATLAB and other languages image processing And many general algorithms in computer vision.

OpenCV is written in C + + language. It has C + +, PythonJava and MATLAB Interface and supports Windows, Linux, Android and Mac OS. OpenCV mainly focuses on real-time visual applications and uses MMX and SSE instructions when available. Now it also provides support for C#, Ch, Ruby and GO.

Software download and installation

Qt5.12.6

Download address: Qt5.12

Select 5.12.6.

Select the windows environment.

Below the "Qt 5.12.6" node are the functional modules of Qt, including modules for different compilers and platforms. These modules include the following contents:

  • MinGW 7.3.0 32-bit compiler module. MinGW is the abbreviation of Minimalist GNU for Windows. MinGW is the collection of GNU tool sets used on Windows platform.
  • Module for UWP compilation. UWP is the abbreviation of Universal Windows Platform in Windows 10. There are different compiler types of UWP.
  • MSVC compiler module for windows platform, such as msvc2017 32-bit and msvc2017 64 bit. To install the module of MSVC compiler, you need to have the corresponding version of Visual Studio installed on your computer.
  • Modules for the Android platform, such as Android x86 and Android ARMv7.
  • Sources is the source program of Qt.
  • Qt Charts is a two-dimensional chart module, which is used to draw commonly used two-dimensional charts such as histogram, pie chart and curve chart.
  • Qt Data Visualization is a three-dimensional data chart module, which is used for three-dimensional display of data, such as three-dimensional spatial distribution of scattered points, three-dimensional surface, etc.
  • Qt Purchasing, Qt WebEngine, Qt Network Auth(TP) and other modules. TP in brackets indicates technical preview.
  • Qt Scritp (Deprecated) is a script module. The "Deprecated" in parentheses indicates that it is an outdated module.

Under the "Tools" node are some tool software, including the following contents:

    • Qt Creator 4.10.1 is an IDE for Qt program development.
    • MinGW 7.3.0 is the MinGW compilation tool chain.
    • Strawberry Perl is a perl language tool.

Cmake

Download address: https://cmake.org/download/

Click download.

Select Windows 64 bit.

After downloading, double-click to install.

2. Agree to the agreement. Check and click [next]

3. Check the red box in the figure, and then click [next]

4. Select a path and click [next].

The installation path can be modified according to your needs. [suggestion] the path name is in English, and does not contain Chinese and spaces

5. Start installation. Click [Install]

6. Please wait patiently during the installation process

7. Installation is completed. Click Finish

Download and install

Python

Python 3.x: download

Install Python

Python 2.7...x: download

Click Python 2 7.17.

Click Windows x86-64 MSI installer.

Double click Install.

[the external link image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-zi1ynAdv-1624958304216)(image-20210628152257357.png)]

Click next.

OpenCV

Download address: OpenCV3.4.14

Click Windows, the official website download is a little slow, you can find other places to download Baidu.

Click Get Updates.

Double click exe to install.

Select the installation directory – click Extract.

Select the installation directory.

After installation, find opencv in the installation directory.

Configure system environment

Configure MinGW environment

Add MinGW environment variable

Add the Path of MinGW under Path, check the system environment variable, and skip if you confirm that it has been added.

Under win10: start – settings – advanced system settings – environment variables – system environment variables – Path – new – browse – OK – OK – OK.

Note: two paths need to be added for QT configuration system environment variables!

D:\QtCreator\Qt5.12.6\Tools\mingw730_32\bin
D:\QtCreator\Qt5.12.6\Tools\mingw730_64\bin
D:\QtCreator\Qt5.12.6\5.12.6\mingw73_32\bin
D:\QtCreator\Qt5.12.6\5.12.6\mingw73_64\bin

Make environment variables effective

Open the command prompt CMD, run set PATH=C:, change the environment variable of the current window task, and close the CMD.

Open another CMD again, run echo% path%, display the latest environment variable, and you will find that the MinGW environment variable just added has taken effect.

Configure OpenCV environment

Note: configure system environment variables!

G:\opencv\OpenCV3.4.14\opencv\build\x64

Configure CMake environment

Check whether the installation is successful

If you enter cmake and some information of cmake can be displayed, the installation is successful, as shown in the following figure:

Add CMake environment variable

Add the Path of CMake under Path, check the system environment variable, and skip if you confirm that it has been added.

Under win10: start – settings – advanced system settings – environment variables – system environment variables – Path – new – browse – OK – OK – OK.

D:\CMake\bin;

Make environment variables effective

Open the command prompt CMD, run set PATH=C:, change the environment variable of the current window task, and close the CMD.

Open another cmd again, run echo% path%, display the latest environment variable, and you will find that the MinGW environment variable just added has taken effect. Open cmd black window,

Configure Python environment

Python2.7 and python 3 should not be installed at the same time

Generate Makefile for OpenCV

Create build folder

Create a folder for storing compiled files.

CMake basic configuration

There are dependencies between opencv and cmake versions.

Configure source path and compile output path

Run as an administrator, add the source path and compile the output path.

Configure local compiler

Click configure – MinGW Makefiles – Specify native compilers – next

Configure compiler path

Configure the compiler path, here is mingw, and then finish.

C: D:/Qt/Qt5.12.6/Tools/mingw730_32/bin/gcc.exe
C++: D:/Qt/Qt5.12.6/Tools/mingw730_32/bin/g++.exe

##

Configure configuration options

Configuration problem solving

See CMake generate FAQs.

Configure WITH_OPENGL/WITH_QT/WITH_IPP options

Check WITH_OPENGL.

Check WITH_QT.

Uncheck WITH_IPP, otherwise there will be an error when running the command line later!!

Click Configure.

Configure QT_MAKE_EXECUTABLE

Set QT_MAKE_EXECUTABLE is D: / qtcreator / Qt5 12.6/5.12.6/mingw73_ 32/bin/qmake. exe

Note: this item is not available. You need to click Add Entry to add it

Add complete.

Configure Qt5_DIR

Qt5_DIR is set to: D: / qtcreator / Qt5 12.6/5.12.6/mingw73_ 32/lib/cmake/Qt5

Click Configure.

  • Set qt5current_ Dir is D: / qtcreator / Qt5 12.6/5.12.6/mingw73_ 32/lib/cmake/Qt5Concurrent

  • Set Qt5Core_DIR is D: / qtcreator / Qt5 12.6/5.12.6/mingw73_ 32/lib/cmake/Qt5Core

  • Set Qt5Gui_DIR is D: / qtcreator / Qt5 12.6/5.12.6/mingw73_ 32/lib/cmake/Qt5Gui

  • Set Qt5Test_DIR is D: / qtcreator / Qt5 12.6/5.12.6/mingw73_ 32/lib/cmake/Qt5Test

  • Set Qt5Widgets_DIR is D: / qtcreator / Qt5 12.6/5.12.6/mingw73_ 32/lib/cmake/Qt5Widgets

  • Set Qt5OpenGL_DIR is D: / qtcreator / Qt5 12.6/5.12.6/mingw73_ 32/lib/cmake/Qt5OpenGL

  • Set cmake_ BUILD_ The type is Release or relewithdebinfo

    Click Configure.

Configure Debug/Release

Set as Release or relewithdebinfo according to requirements.

Generate Makefile

When the message shows Configuring done and there are no errors, click the generate button.

After generation, do not close CMake first. If there are errors in subsequent compilation, change the configuration. Reconfigure generate mingw32 make.

Compiling OpenCV from windows command line MinGW

So we can directly use the MinGW compiler to generate executable files.

Single / multithreaded compilation

Query computer thread

Right click start – device manager – processor. A few columns indicate how many threads the computer supports

Command line compilation

Open the windows command line tool.

Enter the build directory.

cd /d G:\opencv\OpenCV3.4.14\opencv-build

Enter mingw32-make -j5. If an error occurs, please see the following common errors in compiling OpenCV. Otherwise, execute mingw32-make install to complete the installation.

Compilation is complete.

OpenCV installation

install

Installation command: mingw32 make install

installation is complete

Add OpenCV to environment variable

Add the OpenCV system environment variable. If you confirm that it has been added, skip.

Under win10: start – settings – advanced system settings – environment variables – system environment variables – Path – new – browse – OK – OK – OK.

G:\opencv\OpenCV3.4.14\opencv-build\install\x64\mingw\bin

Open the command prompt CMD, run set PATH=C:, change the environment variable of the current window task, and close the CMD.

Open another CMD again, run echo% path%, display the latest environment variable, and you will find that the MinGW environment variable just added has taken effect.

Qt open picture

Create QtMainWindow project

Create a window project.

Select the storage location of the project, and then click next.

next step.

next step.

next step.

Done.

Add OpenCV path to. pro file

Modify according to your own path.

win32 {
    INCLUDEPATH += G:\opencv\OpenCV3.4.14\opencv-build\install\include
    LIBS += G:\opencv\OpenCV3.4.14\opencv-build\bin\libopencv_*.dll
}

Or:

#debug and release are distinguished because OpenCV has different libraries for them

win32 {
    INCLUDEPATH += G:\opencv\OpenCV3.4.14\opencv-build\install\include
    CONFIG(debug, debug|release): {
    LIBS += G:\opencv\OpenCV3.4.14\opencv-build\install\x64\mingw\bin\libopencv_*d.dll
    } else:CONFIG(release, debug|release): {
        LIBS += -LE:\OpenCV_3.4.14\opencv-build\install\x64\mingw\bin \
          -llibopencv_core3414 \
          -llibopencv_highgui3414 \
          -llibopencv_imgcodecs3414 \
          -llibopencv_imgproc3414 \
          -llibopencv_features2d3414 \
          -llibopencv_calib3d3414
}
}

Test code

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // read an image

    cv::Mat image = cv::imread("H:/qt.png", 1);
    // create image window named "My Image"
    cv::namedWindow("My Image");
    // show the image on window
    cv::imshow("My Image", image);
}

Compile run

Note the file name and path.

Official course

How to setup Qt and openCV on Windows

CMake generate FAQs

Python related configuration issues

missing: PYTHON_EXECUTABLE

CMake error

missing: PYTHON_EXECUTABLE

Solution

Installing Python 3

Mingw related configuration problems

Configure CMAKE_MAKE_PROGRAM

CMake error

Click configure and an error cmake will appear_ MAKE_ PROGRAM.

Solution

Check Advanced and add mingw32 make. In QT directory exe .

D:\QtCreator\Qt5.12.6\Tools\mingw730_32\bin

Configure libwinpthread-1 dll

CMake error

Click configure again and an error is reported, "the code execution cannot continue because libwinpthread-1.dll cannot be found".

Solution

C: \ QT \ tools \ mingw530_ Libwinpthread-1 under 32 \ bin DLL or C: \ QT \ tools \ mingw530_ Libwinpthread-1 under 32 \ bin Copy DLL to
32-bit system: C:\Windows\System32
64 bit system: C:\Windows\SysWOW64

Common errors in compiling OpenCV

FFMPEG: Download failed missing file

CMake error

Usually three errors of the same type.

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:

  G:/opencv/OpenCV3.4.14/opencv-build/CMakeDownloadLog.txt

Call Stack (most recent call first):
  3rdparty/ffmpeg/ffmpeg.cmake:20 (ocv_download)
  cmake/OpenCVFindLibsVideo.cmake:227 (download_win_ffmpeg)
  CMakeLists.txt:699 (include)

Solution

CMakeDownloadLog.txt example:

#use_cache "D:/study/opencv-4.0.0/.cache"
#do_copy "opencv_ffmpeg.dll" "849286ccc527c99e5a218b67f13c6e8c" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/759a23e24ab787a0979f8a93103dcc3105ec10c1/ffmpeg/opencv_ffmpeg.dll" "D:/study/opencv_with_contrib_test_sln/3rdparty/ffmpeg"

These two sentences mean to say opencv_ffmpeg.dll(its md5 The signature is 849286 ccc527c99e5a218b67f13c6e8c,The download address is  "https://raw.githubusercontent.com/opencv/opencv_3rdparty/759a23e24ab787a0979f8a93103dcc3105ec10c1/ffmpeg/opencv_ffmpeg.dll" )
 from "D:/study/opencv-4.0.0/.cache" copy to "D:/study/opencv_with_contrib_test_sln/3rdparty/ffmpeg"Directory.

#missing "D:/study/opencv_with_contrib_test_sln/3rdparty/ffmpeg/opencv_ffmpeg.dll"
This file does not exist in the destination directory

#cmake_download "D:/study/opencv-4.0.0/.cache/ffmpeg/849286ccc527c99e5a218b67f13c6e8c-opencv_ffmpeg.dll" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/759a23e24ab787a0979f8a93103dcc3105ec10c1/ffmpeg/opencv_ffmpeg.dll"
Download this file to the source code path /.cache/ffmpeg/,And named"md5-file name"

# timeout on name lookup is not supported
# Trying 151.101.108.133...
# TCP_NODELAY set
# connect to 151.101.108.133 port 443 failed: Connection refused
# Failed to connect to raw.githubusercontent.com port 443: Connection refused
# Closing connection 0
#
Failed to connect to the server

Problem 1: the file opencv is missing in the path \ 3rdparty\ffmpeg of the compilation target file_ ffmpeg_ DLL and opencv_ffmpeg_64_dll

Solution 1:

Find cmakedownloadlog. In the path of the compilation target file (e.g.: G: / opencv / opencv3.4.14 / opencv build) Txt, there is opencv in it_ ffmpeg_ DLL and opencv_ffmpeg_64_dll download link:

opencv_ffmpeg_dll:

https://raw.githubusercontent.com/opencv/opencv_3rdparty/e99214251d9f3cde7c48abd46b2259bddc9885b6/ffmpeg/opencv_ffmpeg.dll "G:/opencv/OpenCV3.4.14/opencv-build/3rdparty/ffmpeg"

opencv_ffmpeg_64_dll:

https://raw.githubusercontent.com/opencv/opencv_3rdparty/e99214251d9f3cde7c48abd46b2259bddc9885b6/ffmpeg/opencv_ffmpeg_64.dll "G:/opencv/OpenCV3.4.14/opencv-build/3rdparty/ffmpeg"

Input the two files into the browser address bar respectively (download in another way) and put them in the path of the compilation target file \ 3rdparty\ffmpeg folder (create a new file if not). (e.g.: G: \ opencv \ opencv3.4.14 \ opencv build \ 3rdparty\ffmpeg)

Question 2: opencv_ffmpeg_dll and opencv_ ffmpeg_ 64_ There is a problem with the MD5 check code of DLL

Opencv previously downloaded_ ffmpeg_ dll,opencv_ffmpeg_64_dll is copied into the "path of compilation target file \ 3rdparty\ffmpeg" folder, and an error is still reported after Cmake configure.

Solution 2:

Copy the two files to the "OpenCV decompression path \ opencv\sources\.cache\ffmpeg" folder,

Then it was renamed MD5 OpenCV_ ffmpeg. DLL and MD5 opencv_ ffmpeg_ 64.dll.

Use this MD5 check code to find cmakedownloadlog in the path of compiling the target file (mine: G: \ opencv \ opencv3.4.14 \ opencv build) Txt search.

Note: opencv_ffmpeg_dll and opencv_ ffmpeg_ 64_ The MD5 check code of DLL is different!

Question 3: https://raw.githubusercontent.com/opencv/opencv_3rdparty/759a23e24ab787a0979f8a93103dcc3105ec10c1/ffmpeg/ffmpeg_version.cmake "Can't download directly,

Instead, ffmpeg is turned on directly_ version. Cmake, you can right-click the web page and select Save as ffmpeg_version.cmake.txt, and then change to ffmpeg_version.cmake. Here, if you create a new txt, then copy the content on the web page directly, and then the suffix is Cmake does not work. It will prompt md5 mismatch.

In path to opencv / sources / 3rdparty / ffmpeg / ffmpeg Cmake edit ffmpeg Cmake open the file ffmpeg in "path to your OpenCV\opencv\sourcesrdparty\ffmpeg" Cmake, change its content to:

message(STATUS "FFMPEG: Package successfully downloaded")
include(${CMAKE_CURRENT_LIST_DIR}/ffmpeg_version.cmake)

Note: different versions of OpenCV correspond to OpenCV_ ffmpeg. The md5 signature of missing files such as DLL is different

FFMPEG: Download failed missing file

CMake error

Usually three errors of the same type.

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:

  G:/opencv/OpenCV3.4.14/opencv-build/CMakeDownloadLog.txt

Call Stack (most recent call first):
  3rdparty/ffmpeg/ffmpeg.cmake:20 (ocv_download)
  cmake/OpenCVFindLibsVideo.cmake:227 (download_win_ffmpeg)
  CMakeLists.txt:699 (include)

Solution

1. First go to GitHub to download the corresponding library

Link: opencv/opencv_3rdparty It is recommended not to clone the whole warehouse. It seems to be large and slow.

2. Find the hash value of branch and commit records

The corresponding location of FFmpeg is path to opencv / sources / 3rdparty / FFmpeg / FFmpeg cmake

In line 1, you can find the branch name to download, that is Binary branch name: ffmpeg/master_20171009
 In line 3, you can find the hash value of the corresponding submission record, i.e. 66 b1fed06cf3510235f367f96aa26da5cb234a15

3. Download the compressed package

github found branch.

OpenCV3.3.1 ffmpeg.

4. Unzip the file

5. Copy files

Ffmpeg in the ffmpeg directory_ version. cmake,opencv_videoio_ffmpeg.dll ,opencv_ videoio_ ffmpeg_ Copy 64.dll to where to build the binaries\opencvrdparty\ffmpeg directory.

6. Change name

Then it was renamed MD5 OpenCV_ ffmpeg. DLL and MD5 opencv_ ffmpeg_ 64.dll and MD5 ffmpeg_ version. cmake.

Use this MD5 check code to find cmakedownloadlog in the path of compiling the target file (mine: G: \ opencv \ opencv3.4.14 \ opencv build) Txt search.

Note: opencv_ffmpeg_dll and opencv_ ffmpeg_ 64_ The MD5 check code of DLL is different!

7. Configure ffmpeg,

Note: do not let CMake download overwrite the manually downloaded files.

Edit ffmpeg Cmake open the file ffmpeg in "path to your OpenCV\opencv\sourcesrdparty\ffmpeg" cmake ,

Amend its content to:

message(STATUS "FFMPEG: Package successfully downloaded")
include(${CMAKE_CURRENT_LIST_DIR}/ffmpeg_version.cmake)

Or:

ffmpeg configuration completed!!!

Ippicv: download failed missing file

CMake error

Solution

1. First go to GitHub to download the corresponding library

Link: opencv/opencv_3rdparty It is recommended not to clone the whole warehouse. It seems to be large and slow.

2. Find the hash value of branch and commit records

The corresponding location of ippicv is path to opencv / sources3rdparty / ippicv / ippicv cmake

You can find the branch name you want to download on line 26(Here with win64 take as an example). Can pass OPENCV_ICV_NAME Variable definition, such as: set(OPENCV_ICV_NAME "ippicv_2020_win_intel64_20191018_general.zip"),If the time is 20191018, select the corresponding branch.
In line 5, you can find the hash value of the corresponding submission record, that is a56b6ac6f030c312b2dce17430eef13aed9af274

3. Download the compressed package

github found branch.

OpenCV3.3.1 ippicv.

4. Unzip the file

5. Copy files

Ippicv_ Copy the win folder to the where to build the binaries\opencvrdparty\ippicv directory. The ippicv directory may not exist. You can create it yourself. ippicv_ Depending on the system, win may have other names. All of them are in the files downloaded in the previous steps. Just unzip them.

6. Configure ippicv

Note: do not let CMake download overwrite the manually downloaded files.

#
# The script downloads ICV package
#
# On return this will define:
# OPENCV_ICV_PATH - path to unpacked downloaded package
#

function(_icv_downloader)
  # Commit SHA in the opencv_3rdparty repo
  set(IPPICV_BINARIES_COMMIT "81a676001ca8075ada498583e4166079e5744668")
  # Define actual ICV versions
  if(APPLE)
    set(OPENCV_ICV_PACKAGE_NAME "ippicv_macosx_20151201.tgz")
    set(OPENCV_ICV_PACKAGE_HASH "4ff1fde9a7cfdfe7250bfcd8334e0f2f")
    set(OPENCV_ICV_PLATFORM "macosx")
    set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_osx")
  elseif(UNIX)
    if(ANDROID AND NOT (ANDROID_ABI STREQUAL x86 OR ANDROID_ABI STREQUAL x86_64))
      return()
    endif()
    set(OPENCV_ICV_PACKAGE_NAME "ippicv_linux_20151201.tgz")
    set(OPENCV_ICV_PACKAGE_HASH "808b791a6eac9ed78d32a7666804320e")
    set(OPENCV_ICV_PLATFORM "linux")
    set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_lnx")
  elseif(WIN32 AND NOT ARM)
    set(OPENCV_ICV_PACKAGE_NAME "ippicv_windows_20151201.zip")
    set(OPENCV_ICV_PACKAGE_HASH "04e81ce5d0e329c3fbc606ae32cad44d")
    set(OPENCV_ICV_PLATFORM "windows")
    set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_win")
  else()
    return() # Not supported
  endif()

  set(OPENCV_ICV_UNPACK_PATH "${CMAKE_CURRENT_LIST_DIR}/unpack")
  set(OPENCV_ICV_PATH "${OPENCV_ICV_UNPACK_PATH}${OPENCV_ICV_PACKAGE_SUBDIR}")

  message(STATUS "ICV: Package successfully downloaded")
  set(OPENCV_ICV_PATH "${OPENCV_ICV_PATH}" PARENT_SCOPE)
endfunction()

_icv_downloader()


After reinstalling OpenCV, CMake clicks configure and an error is reported

Useless character... invalid

Solution: if CMake is found, the default source code and binaries will remain unchanged - > delete all contents in the buildoupencv folder and rebuild buildoupencv (compiled target folder) - >

Put the latest installation path of OpenCV in source code, and then follow the engineering configuration of Cmake. It is normal

Note: after reinstalling OpenCV, the system environment variables should also be changed!

Missing time h

error: 'time' was not declared in this scope

Quote in the header

#include <sys/time.h>

MinGW compilation error

xxx is not an internal or external command

CMake error

D:\ProgramFiles is not an internal or external command

Solution

Add a path, such as D: \ program files \ Qt5 9.0Tools\mingw530_ 32\bin

be careful: QT Two paths need to be added to configure the system environment variables,The two paths are slightly different. Be careful:

D:\ProgramFiles\Qt5.9.0\Tools\mingw530_32\bin
D:\ProgramFiles\Qt5.9.0\5.9\mingw53_32\bin


be careful: window The slash behind the path below is\,The browser is/

C In the back is—— D:\ProgramFiles\Qt5.9.0\Tools\mingw530_32\bin**/**gcc.exe
C++In the back is -- D: \ program files \ Qt5 9.0\Tools\mingw530_ 32\bin**/**g++.exe

C Behind is—— D:\ProgramFiles\Qt5.9.0\Tools\mingw530_32\bin\gcc.exe
C++In the back is—— D:\ProgramFiles\Qt5.9.0\Tools\mingw530_32\bin\g++.exe

... windres.exe: unknown option – W ...

CMake error

 ... windres.exe: unknown option -- W ...perhaps``
 
 - FORMAT is one of rc, res, or coff, and is deduced from the file name
 - extension if not specified. A single file name is an input file.
 - No input-file is stdin, default rc. No output-file is stdout, default rc.

Solution

In the cmake GUI compilation configuration:

  • Uncheck ENABLE_PRECOMPILED_HEADERS

Then re configure generate mingw32 make

identifier 'nullptr' is a keyword in C++11

CMake error

D:\opencv-3.4.1\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc:94:3: warning: identifier 'nullptr' is a keyword in C++11 [-Wc++0x-compat]
   return s == nullptr || *s == 0;
   ^
D:\opencv-3.4.1\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc: In function 'bool google::protobuf::internal::win32::{anonymous}::null_or_empty(const char_type*)':
D:\opencv-3.4.1\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc:94:15: error: 'nullptr' was not declared in this scope
   return s == nullptr || *s == 0;
               ^
3rdparty\protobuf\CMakeFiles\libprotobuf.dir\build.make:412: recipe for target '3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj' failed
mingw32-make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj] Error 1
CMakeFiles\Makefile2:710: recipe for target '3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all' failed
mingw32-make[1]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all] Error 2
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2<br>MakeOpenCV_nullptr_Error

Solution

In the cmake GUI compilation configuration:

Check ENABLE_CXX11, then re configure generate mingw32 make, add the opencv compiled library to the environment variable, and add e: \ OpenCV to the system variable Path_ 3.3.1\opencv-build\install\x86\mingw\bin

sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA

CMake error

..opencv/sources/modules/videoio/src/cap_dshow.cpp...
... 'sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA' was not declared in this scope ...
perhaps
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

Solution

Modify E:\OpenCV_3.3.1\opencv\sources\modules\videoio\src\cap_dshow.cpp file, above the #include "DShow.h" line

Add a line #define NO_DSHOW_STRSAFE

Then re configure generate mingw32 make

Building CXX object modules/python3

CMake error

[ 98%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.obj

C:/Qt/Tools/mingw530_32/i686-w64-mingw32/include/c++/cmath:1119:11: error: '::hypot' has not been declared

using ::hypot;

Solution

hold CMake In configuration BUILD_opencv_python3 And the one below BUILD_opencv_python3_bindings_generator of off fall(Remove the check in the back)

Then re configure generate mingw32 make

**Note: * * if opencv is not used_ Python, you need to uncheck build in the CMake interface_ opencv_python and opencv_python related options, otherwise the compilation will not pass.

recipe for target 'all' failed

CMake error

If multithreaded compilation is used, it will lead to an error, but the error information is not clear, such as:

Makefile:161: recipe for target 'all' failed

mingw32-make: *** [all] Error 2

Solution

Use single threaded compilation:

mingw32-make

To view the detailed error prompt, and then solve it according to the specific situation.

C + + error

identifier 'nullptr' is a keyword in C++11 error

performance

D:\opencv-3.4.1\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc:94:3: warning: identifier ``'nullptr'` `is a keyword in C++11 [-Wc++0x-compat]
  ``return` `s == ``nullptr` `|| *s == 0;
  ``^
D:\opencv-3.4.1\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc: In function ``'bool google::protobuf::internal::win32::{anonymous}::null_or_empty(const char_type*)'``:
D:\opencv-3.4.1\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc:94:15: error: ``'nullptr'` `was not declared in ``this` `scope
  ``return` `s == ``nullptr` `|| *s == 0;
        ``^
3rdparty\protobuf\CMakeFiles\libprotobuf.dir\build.make:412: recipe ``for` `target ``'3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj'` `failed
mingw32-make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj] Error 1
CMakeFiles\Makefile2:710: recipe ``for` `target ``'3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all'` `failed
mingw32-make[1]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all] Error 2
Makefile:161: recipe ``for` `target ``'all'` `failed
mingw32-make: *** [all] Error 2<br>MakeOpenCV_nullptr_Error

solve

In the cmake GUI compilation configuration:

Check ENABLE_CXX11

Compile check

  • Open the "cmakeopencvcompilerioptions. Cmake" file in the "opencv installation directory \ sources" and add the statement in it_ extra_ compiler_ Option (- werror = non virtual dTOR) and change it to # add_extra_compiler_option(-Werror=non-virtual-dtor)

  • During compilation, you can add "- i" at the end of the statement to ignore errors, that is, use the statement:

    • mingw32-make -i
    • mingw32-make install -i
  • Check whether the path of CMake contains spaces. If so, uninstall and reinstall

  • Check whether the system paths to be added have been added

  • Check whether CMake's Configure is selected as MinGW Makefiles

  • Locate the location of C and C + + compilers provided by Qt:

    • The location of C compiler is - QT installation path \ Qt5 9.0\Tools\mingw530_ 32\bin****gcc. exe
    • The location of C + + compiler is - QT installation path \ Qt5 9.0\Tools\mingw530_ 32\bin****g++. exe
  • Find the problem in "binary object file path / CMake/CMakeOutput.log" and "binary object file path / CMake/CMakeError.log" to find the solution

  • Unable to compile and run, prompting that the compiler cannot be found, possibly because there are Chinese symbols under the directory

  • The cursor cannot be displayed in the compiler. This problem may be caused by using Google input method. Modify the embedded editing mode

  • The compiler can run, but the exe file cannot run in the debug mode, prompting "unable to start this program because qt5core.dll is missing in the program". The problem may be that the environment variable is not set, just add the environment variable

Topics: Programmer