2016-09-07 3 views
0

Я новичок в OpenCV и использую его в Qt Creator. Я хочу отобразить изображение. Мой код:Изображение не отображается в OpenCV в Qt

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

#include <iostream> 
#include <string> 

using namespace cv; 
using namespace std; 

int main() 
{ 
    Mat image=imread("C:/Users/richa/Desktop/IMG-20150324-WA0001.jpg",CV_LOAD_IMAGE_COLOR); // Read the file 


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

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

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

Выход - это только консольное окно без изображения. Также программа выходит с кодом -1073741511. Почему изображение не загружается в новом окне? Скриншот: enter image description here

+0

Проблема может быть, что вы работаете с программой во внешнем терминале. Просто настройте QtCreator, чтобы отключить его в «Проверить проекты -> Параметры запуска -> Запустить в терминале». – ikaro

ответ

0

Try:

int main() 
{ 
    Mat image=imread("C:/Users/richa/Desktop/IMG-20150324-WA0001.jpg",CV_LOAD_IMAGE_COLOR); // Read the file 


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

    namedWindow("Image",WINDOW_AUTOSIZE); // Create a window for display. 

    for(;;)//infinite loop 
    { 
    imshow("Image", image);    // Show our image inside it. 

    char c=waitKey(10); // Wait for a keystroke in the window for 10ms, then move on 
    if(c=='b' || c=='B')//if b is pressed 
    break; 
    } 
    return 0; 
} 
Смежные вопросы