0

I want to build an application using the OpenCV library built with cmake. First I downloaded the sources for opencv4.5.5. I created in that folder a subfolder mingwbuild and from there I can the command "cmake ../ -G "MinGW Makefiles" Then I ran the command "mingw32-make install" and it took 2 hours to compile. I then used cmake again to build a project, like described in the first answer here: Configuring an c++ OpenCV project with Cmake When I then ran the generated .exe, it would give me a runtime error "Qt5OpenGl.dll and Qt5Test.dll could not be found"

So I downloaded QtOpenGl.dll with MSYS2 from here https://packages.msys2.org/package/mingw-w64-x86_64-qt5-base with the command "pacman -S mingw-w64-x86_64-qt5-base" When I then run my opencvtest.exe , it says that it could not find the entry point of some method in QtOpenGl.dll . So the version or something must be wrong?

When searching for the package in the MSYS2 terminal, it says there are 10 packages I can download and install. The first four are:

$ pacman -Ss qt5-base

mingw32/mingw-w64-i686-qt5-base 5.15.3+kde+r174-2 (mingw-w64-i686-qt5) A cross-platform application and UI framework (mingw-w64) mingw32/mingw-w64-i686-qt5-base-debug 5.15.3+kde+r174-2 (mingw-w64-i686-qt5-debug) A cross-platform application and UI framework (mingw-w64) mingw64/mingw-w64-x86_64-qt5-base 5.15.3+kde+r174-2 (mingw-w64-x86_64-qt5) [installed] A cross-platform application and UI framework (mingw-w64) mingw64/mingw-w64-x86_64-qt5-base-debug 5.15.3+kde+r174-2 (mingw-w64-x86_64-qt5-debug)

Maybe if I choose the release package, I also have to set the option -DCMAKE_BUILD_TYPE=Release when invoking cmake?

Option x86 means 64-bit package and without x86, it means 32-bit packages. How can I figure out which of these I do need?

Any help is appreciated.

user172501
  • 332
  • 2
  • 11

1 Answers1

0

I finally managed to compile my OpenCVApp

The key was to work only in the MSYS2 MinGW x64 shell.

First I needed to install cmake like so:

pacman -S mingw-w64-x86_64-cmake

Then I had to install opencv with pacman like so:

pacman -S /mingw-w64-x86_64-opencv

The Qt5, I had to install like so:

pacman -S mingw-w64-x86_64-qt5-base

Then I created a new directory with src/main.cpp and CMakeLists.txt inside it like so:

Here CMakeLists.txt

 cmake_minimum_required(VERSION 2.8) 
    PROJECT (opencvtest)
    find_package(OpenCV REQUIRED )
    set( NAME_SRC
        src/main.cpp    
    )
    
    set( NAME_HEADERS       
         include/header.h
    )
    
    INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )
    link_directories( ${CMAKE_BINARY_DIR}/bin)
    set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
    add_executable( opencvtest ${NAME_SRC} ${NAME_HEADERS} )
    
    target_link_libraries( opencvtest ${OpenCV_LIBS} )

Here main.cpp

#include <iostream>
#include <sstream>
#include <string>
#include <fstream>

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;

const cv::Vec3b color_azure{ 255, 129, 0 };
const cv::Vec3b color_violet{ 255, 0, 127 };
const cv::Vec3b color_black {0,0,0};


int main() {
    cout << "App started" << endl;
    cv::Mat image = cv::Mat(cv::Size(800, 600), CV_8UC3, color_black);

    std::vector<cv::Point> vs(5);
    vs[0] = cv::Point(200, 450);
    vs[1] = cv::Point(600, 250);
    vs[2] = cv::Point(400, 50);
    vs[3] = cv::Point(200, 250);
    vs[4] = cv::Point(600, 450);

    std::vector<int> nk(9);
    nk[0] = 0;
    nk[1] = 1;
    nk[2] = 2;
    nk[3] = 3;
    nk[4] = 4;
    nk[5] = 0;
    nk[6] = 3;
    nk[7] = 1;
    nk[8] = 4;
    
    std::stringstream ss("Das-ist-das-Haus-vom-Ni-ko-laus");
    std::vector<std::string> silben(9);

    int j = 0;
    while (ss.good())
    {
        std::string substr;
        getline(ss, substr, '-');
        silben[j++] = substr + "-";
    }

    for (int i = 0; i < 8; i++) {
        cv::line(image, vs[nk[i]], vs[nk[i + 1]], color_azure, 5);
        cv::putText(image, silben[i], cv::Point(i*60, 475),
            cv::FONT_HERSHEY_PLAIN, 1, color_violet, 2);
        cv::imshow("Image", image);
        cv::waitKey();
    }

    cv::imshow("Image", image);
    cv::waitKey(0);
    return 0;

   
}

Then compiling and running worked fine:

mkdir buildmingw
cd buildmingw
cmake .. -G "MinGW Makefiles"
mingw32-make 
bin/opencvtest.exe
user172501
  • 332
  • 2
  • 11