0

I'm encountering an issue when trying to run an executable built with CLion and OpenCV. The program compiles successfully, but when I attempt to run it, I receive the following error message: C:\Users\ahoiz\CLionProjects\Opencv\cmake-build-debug\Opencv.exe Process finished with exit code -1073741511 (0xC0000139)

#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"

#include <iostream>
#include <ctype.h>

using namespace cv;
using namespace std;

static void help()
{
    // print a welcome message, and the OpenCV version
    cout << "\nThis is a demo of Lukas-Kanade optical flow lkdemo(),\n"
            "Using OpenCV version " << CV_VERSION << endl;
    cout << "\nIt uses camera by default, but you can provide a path to video as an argument.\n";
    cout << "\nHot keys: \n"
            "\tESC - quit the program\n"
            "\tr - auto-initialize tracking\n"
            "\tc - delete all the points\n"
            "\tn - switch the \"night\" mode on/off\n"
            "To add/remove a feature point click it\n" << endl;
}

Point2f point;
bool addRemovePt = false;

static void onMouse( int event, int x, int y, int /*flags*/, void* /*param*/ )
{
    if( event == EVENT_LBUTTONDOWN )
    {
        point = Point2f((float)x, (float)y);
        addRemovePt = true;
    }
}

int main( int argc, char** argv )
{
    VideoCapture cap;
    TermCriteria termcrit(TermCriteria::COUNT|TermCriteria::EPS,20,0.03);
    Size subPixWinSize(10,10), winSize(31,31);

    const int MAX_COUNT = 500;
    bool needToInit = false;
    bool nightMode = false;

    help();
    cv::CommandLineParser parser(argc, argv, "{@input|0|}");
    string input = parser.get<string>("@input");

    if( input.size() == 1 && isdigit(input[0]) )
        cap.open(input[0] - '0');
    else
        cap.open(input);

    if( !cap.isOpened() )
    {
        cout << "Could not initialize capturing...\n";
        return 0;
    }

    namedWindow( "LK Demo", 1 );
    setMouseCallback( "LK Demo", onMouse, 0 );

    Mat gray, prevGray, image, frame;
    vector<Point2f> points[2];

    for(;;)
    {
        cap >> frame;
        if( frame.empty() )
            break;

        frame.copyTo(image);
        cvtColor(image, gray, COLOR_BGR2GRAY);

        if( nightMode )
            image = Scalar::all(0);

        if( needToInit )
        {
            // automatic initialization
            goodFeaturesToTrack(gray, points[1], MAX_COUNT, 0.01, 10, Mat(), 3, 3, 0, 0.04);
            cornerSubPix(gray, points[1], subPixWinSize, Size(-1,-1), termcrit);
            addRemovePt = false;
        }
        else if( !points[0].empty() )
        {
            vector<uchar> status;
            vector<float> err;
            if(prevGray.empty())
                gray.copyTo(prevGray);
            calcOpticalFlowPyrLK(prevGray, gray, points[0], points[1], status, err, winSize,
                                 3, termcrit, 0, 0.001);
            size_t i, k;
            for( i = k = 0; i < points[1].size(); i++ )
            {
                if( addRemovePt )
                {
                    if( norm(point - points[1][i]) <= 5 )
                    {
                        addRemovePt = false;
                        continue;
                    }
                }

                if( !status[i] )
                    continue;

                points[1][k++] = points[1][i];
                circle( image, points[1][i], 3, Scalar(0,255,0), -1, 8);
            }
            points[1].resize(k);
        }

        if( addRemovePt && points[1].size() < (size_t)MAX_COUNT )
        {
            vector<Point2f> tmp;
            tmp.push_back(point);
            cornerSubPix( gray, tmp, winSize, Size(-1,-1), termcrit);
            points[1].push_back(tmp[0]);
            addRemovePt = false;
        }

        needToInit = false;
        imshow("LK Demo", image);

        char c = (char)waitKey(10);
        if( c == 27 )
            break;
        switch( c )
        {
            case 'r':
                needToInit = true;
                break;
            case 'c':
                points[0].clear();
                points[1].clear();
                break;
            case 'n':
                nightMode = !nightMode;
                break;
        }

        std::swap(points[1], points[0]);
        cv::swap(prevGray, gray);
    }

    return 0;
}

I get the error statement:

Process finished with exit code -1073741511 (0xC0000139)

As for the content in my CMakeLists.txt, it looks like this:

cmake_minimum_required(VERSION 3.25)
project(Opencv)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23")
set(CMAKE_AUTOMOC OFF)
set(CMAKE_AUTOUIC OFF)
set(CMAKE_AUTOURCC OFF)

# Where to find CMake modules and OpenCV
set(OpenCV_DIR "E:/Software/opencv/Mingw-build/install")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

set(CMAKE_PREFIX_PATH "E:/Software/Qt/6.5.2/mingw_64")
find_package(Qt6 REQUIRED COMPONENTS Widgets Core Gui)


add_executable(Opencv "main.cpp")

# add libs you need
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_video opencv_imgcodecs)

# linking
target_link_libraries(Opencv ${OpenCV_LIBS} Qt6::Widgets Qt6::Core Qt6::Gui)

Could someone please provide insights into what might be causing this error and how I can go about resolving it? Are there specific DLLs or environment variables that I need to address? Any debugging steps or tools I should use to track down the source of this issue would be greatly appreciated. Thank you in advance for your help!

SteveAhoy
  • 1
  • 1
  • https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems – pptaszni Aug 28 '23 at 09:03
  • Perhaps your problem is [dll hell](https://en.wikipedia.org/wiki/DLL_Hell) likely caused by having multiple (and incompatible) versions of the dependent dlls installed in your windows `PATH` environment variable. – drescherjm Aug 28 '23 at 14:15
  • This software may help show you the dll dependencies of your application: [https://github.com/lucasg/Dependencies](https://github.com/lucasg/Dependencies) – drescherjm Aug 28 '23 at 14:17
  • Hey @drescherjm, your DLL tip was spot on! Removed libstdc-++6.dll from PATH and got it rolling in terminal. Still wrestling with -1073741511 (0xC0000139) error in CLion though. Any insights into this twist? Thanks a ton for the tip! – SteveAhoy Aug 29 '23 at 05:57
  • Maybe CLion has its own `PATH` environment variable / sets additional PATHs – drescherjm Aug 29 '23 at 14:05

0 Answers0