I have a problem to display an image on Qt Creator with OpenCV library.
I have a program that displays an image when a button is pressed. When I run it, it gives me
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\\builds\\2_4_PackSlave-win64-vc12-shared\\opencv\\modules\\highgui\\src\\window.cpp, line 261 The program has unexpectedly finished.
using namespace cv;
void MainWindow::on_start_clicked()
{
Mat src = imread("C:/Users/Amr/Documents/untitled7/layout.jpeg",CV_WINDOW_AUTOSIZE);
namedWindow("src",CV_WINDOW_AUTOSIZE);
imshow("src",src);
waitKey(0);
destroyWindow("src");
}
but when i try this program it works very good
using namespace cv;
void MainWindow::on_start_clicked()
{
Mat src (500,500,CV_8UC3,Scalar(255,0,0));
namedWindow("src",CV_WINDOW_AUTOSIZE);
imshow("src",src);
waitKey(0);
destroyWindow("src");
}
I feel that the problem is in the directory but I don't know what it is. I have tried to change /
to \\
or //
but still getting this error.
Assuming that the path is correct, using CV_WINDOW_AUTOSIZE
doesn't make sense. Use IMREAD_XXX
:
Mat src = imread("C:/Users/Amr/Documents/untitled7/layout.jpeg", IMREAD_COLOR);
However, double check the path, and remember that "image.jpeg" is different from "image.jpg". And... are you sure "untitled7" is correct?
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.