简体   繁体   中英

Running OpenCV Program on Windows

I have a simple test program for OpenCV:

#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgcodecs/imgcodecs.hpp"
#include <iostream>

int main(int argc, char **argv){
    std::cout << "HELLO" << std::endl;

    cv::Mat im=cv::imread((argc==2)? argv[1]: "testing.jpg",cv::IMREAD_COLOR);
    if (im.empty()){
        std::cout << "Cannot open image." << std::endl;
    } else {
        cv::namedWindow("DisplayWindow",cv::WINDOW_AUTOSIZE);
        cv::imshow("DisplayWindow",im);
        cv::waitKey(0);
    }
    return 0;
}

However, when run the program does nothing. Hello is not printed to the console, and it does not output an error.

./main
#Nothing.......

It is worth noting that the program terminates, but not in the proper way. (The return value is non-zero) I do not think that this is a linking error, as those would actually output an error.

Any ideas on what is happening and/or how to fix it? I am using a Windows computer if that changes anything.

Turns out the windows cmd prompt actually has some use. (VERY surprising, I gave up on it a long time ago)

I ran the test program from the windows cmd line and it said the following libraries were missing.

libstdc++-6.dll
libgcc_s_dw2-1.dll
libwinpthread-1.dll

To fix the standard C++ and C libraries I just statically linked them using the below command. (This is apparently a common practice on Windows due to issues with version control ):

g++ -static-libgcc -static-libstdc++ ...rest of compile/link cmd...

To fix the winpthread dll I just copied the dll to the bin folder of my program and everything worked!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM