Can not read image in opencv

前端 未结 2 1707
我寻月下人不归
我寻月下人不归 2021-01-17 06:06

I am new to opencv and I am starting to make a simple code to read and display image in gui ,I am working in qt IDE, first I wirte this block of code

#includ         


        
相关标签:
2条回答
  • 2021-01-17 06:41

    it seems that the program does not know where the image is. Try to include main.cpp as one of the libraries that the program will use. That way, the program will be able to find and open the image.

    0 讨论(0)
  • 2021-01-17 07:02

    As you said following code showed you that file not exist:

    QFile file("image.jpg");
         if(file.exists())
             cout<<"\n exist \n"<<endl;
         else
             cout<<"\n not exist \n"<<endl;
    

    Solution:

    First of all, try to set full path to your image. For some reasons Qt search your file in wrong place, so set full path.

    For example:

    cv::Mat image=cv::imread("G:\\2\\qt.jpg");
    QFile file("G:\\2\\qt.jpg");
    if(file.exists())
        cout<<"\n exist \n"<<endl;
    else
        cout<<"\n not exist \n"<<endl;
    

    Or UNIX style:

    cv::Mat image=cv::imread("G:/2/qt.jpg");
    QFile file("G:/2/qt.jpg");
    if(file.exists())
        qDebug()<<"\n exist \n"<<endl;
    else
         qDebug()<<"\n not exist \n"<<endl;
    
    0 讨论(0)
提交回复
热议问题