2016-09-07 23 views
0

OpenCVを初めて使用し、Qt Creatorで使用しています。私はイメージを表示したい。私のコードは:QtのOpenCVで画像が表示されない

#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

問題は、外部端末でプログラムを実行していることが考えられます。 'Check Projects - > Run Settings - > Run in terminal'でQtCreatorを無効にするよう設定してください。 – ikaro

答えて

0

試してみてください。

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; 
} 
関連する問題