我是OpenCV的新手并在Qt Creator中使用它。我想要显示图像。我的代码是:
#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;
}
答案 0 :(得分: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;
}