windows - 尝试使用 OpenCV 库运行示例代码后,进程已完成,退出代码为 -1073741515 (0xC0000135)

标签 windows opencv clion

我一直在尝试在Windows下使用CLion IDE运行OpenCV。当我尝试运行此示例代码来加载和显示图像时

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream> 
using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    if( argc != 2)
    {
     cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
     return -1;
    }

    Mat image;
    image = imread("earth.jpg", CV_LOAD_IMAGE_COLOR);   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.

    waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
}

我收到错误声明:

Process finished with exit code -1073741515 (0xC0000135)

至于我的CMakeLists.txt中的内容,它看起来像这样:

cmake_minimum_required(VERSION 3.6)
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

# Where to find CMake modules and OpenCV
set(OpenCV_DIR "C:\\opencv\\mingw-build\\install")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(openCV main.cpp)

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

# linking
target_link_libraries(openCV ${OpenCV_LIBS})

谢谢你帮我解决这个问题。

最佳答案

您需要在 CLion 启动之前将带有 DLL 的 OpenCV 二进制路径添加到您的 PATH 中。 我从脚本中做到这一点:

=== CLionWithMingwAndOpenCV.bat ==========================
@echo off
set PATH=C:\mingw-w64\x86_64-5.2.0-win32-seh-rt_v4-rev0\mingw64\bin;D:\opencv\release\bin;%PATH%

"C:\Program Files (x86)\JetBrains\CLion XXXX\bin\clion64.exe"
=== ==========================

关于windows - 尝试使用 OpenCV 库运行示例代码后,进程已完成,退出代码为 -1073741515 (0xC0000135),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40273663/

相关文章:

c++ - Mat OpenCv 分配错误

c - 如何在 Clion 中自动生成 .h 文件的函数头?

windows - 为 Windows 7 构建自定义凭证提供程序

windows - 使用 MultiByteToWideChar

python - 'tuple'没有属性。 OpenCV Python

c++ - 最小化单应矩阵中的误差

ide - 在 Mac 计算机上为 c++ 设置 CLION IDE

c++ - CLion 上的 CPPREST SDK 在 Mac 上使用 CMake

windows - 在 Windows 上优雅地终止命令行应用程序

c++ - 在 Win32 上,我可以在一段时间内禁用窗口绘制吗?