Im trying to display an image with opencv but failed. Search google and don't know how the closest one show a debug only
Here the code
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("dom.png");
namedWindow("image", WINDOW_NORMAL);
imshow("image", img);// It stuck here
waitKey(0);
return 0;
}
I tried to put img in Resource File and Source File but still get error. The platform is for x64 .
Exception thrown at 0x00007FFBE404A388 in Opencv_01.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000768258F1B0.
Unhandled exception at 0x00007FFBE404A388 in Opencv_01.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000768258F1B0.
Where have I go wrong?
The problem is that you do not handle the case where if fails to load the image. Perhaps it's not found in the currnet directory of the program.
The way to check that the image was loaded is like this:
int main()
{
Mat img = imread("dom.png");
if(!img.data) {
cout << "Could not load image" << '\n';
return 1;
}
namedWindow("image", WINDOW_NORMAL);
imshow("image", img);// It stuck here
waitKey(0);
return 0;
}
Related
i have tried out almost every format of writing path of that specific image in my code(/,//), even tried out by putting the image into project folder with some respective changes. but still there is an assertion error(without if condition).I tried my best to solve this but still the image not opening. I am a newbie using OpenCV c++ . Please help me I am tired with this error.
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("test.png");
if (!img.data)
{
std::cout << "Image not loaded";
return -1;
}
imshow("Display Image", img);
waitKey(5000);
return 0;
}
I installed OpenCV 2.4.10 and configured it to my Visual Studio 2010. And even I run below code in opencv(c)
My code in opencv:
#include "opencv\highgui.h"
int main(int argc, char** argv)
{
IplImage* img =cvLoadImage("d:\\1.jpg",CV_WINDOW_AUTOSIZE);
cvNamedWindow("example1", CV_WINDOW_AUTOSIZE);
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Exame1");
}
and it works but when I try to use the code given here,with opencv2(c++) but it gives an error (break)
My code in opencv2:
#include "opencv2\opencv.hpp"
using namespace cv;
int main()
{
Mat image = imread("d:\\1.jpg", CV_LOAD_IMAGE_COLOR);
namedWindow("test", WINDOW_AUTOSIZE);
imshow("test", image);
waitKey(0);
return 0;
}
Error(break):
Unhandled exception at 0x7624c41f (KernelBase.dll) in o.exe: Microsoft C++ exception: cv::Exception at memory location 0x0035f63c..
Why is this error just in opencv2?!
I want to work with opencv2
You will have to verify that you are building in debug/release mode based on the build information of the opencv .dll files you are using.
I am trying to save an image after I have processed it but unfortunately I am getting an exception. It is running all the lines except the imwrite command (last command on code), and it's throwing this exception:
Unhandled exception at at 0x000007FEFD0D940D in histogram.exe:
Microsoft C++ exception: cv::Exception at memory location 0x00000000001DF720.
How can I fix this error, and what is causing it?
The code I'm using:
int main(int argc, char *argv[])
{
///Loading image to IplImage
//IplImage *img=cvLoadImage(argv[1]);
IplImage *img;
img = cvLoadImage("phidza.JPG",1);
cvShowImage("Ipl",img);
///converting IplImage to cv::Mat
Mat image=cvarrToMat(img);
imshow("Mat",image);
//std::cout<<"size: " << image.size() .height<< " , "
// << image.size().width << std::endl ;
if (image.empty())
{
cout << "Image cannot be loaded..!!" << endl;
return -1;
}
cvtColor(image, image, CV_BGR2GRAY); //change the color image to grayscale image
Mat img_hist_equalized;
equalizeHist(image, img_hist_equalized); //equalize the histogram
//create windows
//namedWindow("Original Image", CV_WINDOW_AUTOSIZE);
namedWindow("output", CV_WINDOW_AUTOSIZE);
//show the image
//imshow("Original Image", image);
imshow("output", img_hist_equalized);
waitKey(0); //wait for key press
imwrite("../output.jpg", img_hist_equalized); // save image
//cvSaveImage("output.jpg", img);
destroyAllWindows(); //destroy all open windows
return 0;
}
This code segment works fine for me, finally the result image got saved.. Binaries might have got corrupted in your case, So better to rebuild the opencv library.
I'm new to opencv programming, so maybe my question will be very stupid. But i have such problem, i took one sample code, which should enable laptop webcamera to show image in desktop.
#include <opencv\cv.h>
#include <opencv\highgui.h>
using namespace cv;
int main()
{
Mat image; //create Matrix to store image
VideoCapture cap;
cap.open(0); // initialize capture
namedWindow("window", CV_WINDOW_AUTOSIZE); // create window to show image
while(1)
{
cap>>image; // copy webcam stream to image
imshow("window", image); // print image to screen
waitKey(33); // delay 33ms
}
return 0;
}
But when i'm trying to debug it i get an error message.
Unhandled exception at 0x5a16ebe6 in myNewOpenCV.exe: 0xC0000005: Access violation reading location 0x00000018.
But if i put breakpints on
cap>>image;
imshow("window", image); // print image to screen`
and after debuging im taking it off everything work correctly. Maybe someone can help to find a problem. Thanks.
Im using Opencv 2.3.1 on Visual studio 2010 (vc10)
I have configured opencv based on many tutorials and can compile & run C-syntax program like:
#include "StdAfx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main ()
{
IplImage* img = cvLoadImage("D:\cat_helmet.jpg", CV_LOAD_IMAGE_UNCHANGED);
cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
cvShowImage("display", img );
cvWaitKey(0);
return 0;
}
However, I cannot run the C++ syntax program like
#include "StdAfx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
Mat image;
image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR);
if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
imshow( "Display window", image );
waitKey(0);
return 0;
}
I got the error messages (in the function calls: namedWindow, imread, imshow)
First-chance exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.
Unhandled exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.
How can I fix this?
You say that you have followed a multitude of guides and tutorials. I've had great success with this one
http://www.anlak.com/using-opencv-2-3-1-with-visual-studio-2010-tutorial/
The thing is that this guy walks you through the 'park' and helps you unravel two major issues whilst setting up OpenCV 2.3.1; one of which is placement of .dll files in your project folder. The other is a missing .dll 'tbb_debug.dll' (the absense of this .dll is considered a bug in OpenCV 2.3.1).
He also provides some decent code-snippets for your to try out (in c++ syntax).
Good luck.
The above mentioned answers doesn't make sense. I am also facing the same problem. The main reason for this exception is that you are trying to display image (read by imread) which is empty. The main problem in the program is the line
image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR);
I think imread function is not behaving the way it is expected. One more thing, while going through the references i came across a following link:
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat imread(const string& filename, int flags)
Here, imread is used via call by reference method. I am not a C++ expert, but i feel it could be the problem.
int main()
{
std::string imgPath("splash.bmp"); //Add your file name
Mat img = imread(imgPath);
namedWindow( "Example1", WINDOW_AUTOSIZE);
imshow("Example1", img);
waitKey(0);
return 0;
}
This code worked for me. Also, I put the file next to executable to decrease complexity.