I have an application written in visual studio, utilizing OpenCV 2.4.10. The program executes flawlessly in debug mode, but in release mode it crashes on the first command following a VideoCapture::open() call, regardless of whether the call was completed in the constructor or with the method call. I recognize that this is a pretty common occurrence, and that a dll linkage may be the issue, but have been unable to fully identify the problem. Any assistance is greatly appreciated.
Here is the error message:
Unhandled exception at 0x03DE7D43 (opencv_ffmpeg2410.dll) in OpenCVLaserDot.exe: 0xC0000005: Access violation reading location 0x00000000.
Here is the segment of code surrounding the VideoCapture instantiation:
const string DEFAULT_INPUT_FILE = "C:/Users/Tyler/Documents/Visual Studio 2013/Projects/OpenCVLaserDot/Release/a.avi";
VideoCapture cap;
if (inputFile == "1" || inputFile == ""){
cap.open(DEFAULT_INPUT_FILE);
} else {
cap.open(inputFile);
}
if (!cap.isOpened()){
printf("Failed to open video\n");
return -1;
}
Related
I'm using IP webcam android app(It converts mobile camera into IP web camera). I'm running below code in Visual Studio 2015 with OpenCV 3.1.
VideoCapture cap; Mat img;
cap.open("http://192.168.0.101:8080/video?x.mjpeg");
while(waitKey(33)!=27)
{
try{
cap>>img; //code crashes here
if(img.empty())
{
cout<<"camera Closed"<<endl;
break;
}
imshow("Video",img);
} catch(...{}
}
Getting below error.cIf the internet connection is slow or if the Wi-Fi is disconnected in my android device the program crashes
Error:
Exception thrown at 0x0BF2F6F0 (opencv_ffmpeg310.dll) in test.exe:
0xC0000005: Access violation reading location 0x00000020.
If there is a handler for this exception, the program may be safely
continued.
even if the code is wrapped within try catch block, it crashes!
Should I use try {} catch (...) block in source file, if yes, then where should I use this? I referred this link but did not find the right answer.
The following code gives me the uncaught exception (specifically
txtr.loadFromFile("C:/Users/kidz/Documents/Visual Studio 2012/Projects/SFML/Debug/chessboard.gif");
): "Unhandled exception at 0x701ADEF8 (msvcr110.dll) in SFML.exe: 0xC0000005: Access violation reading location 0x05260000."
int _tmain(int argc, wchar_t* argv[]) {
sf::RenderWindow window(sf::VideoMode(512, 512), "ChessPlusPlus", sf::Style::Close);
sf::Sprite chessboard;
sf::Texture txtr;
txtr.loadFromFile("C:/Users/kidz/Documents/Visual Studio 2012/Projects/SFML/Debug/chessboard.gif");
chessboard.setTexture(txtr);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
window.clear();
window.draw(chessboard);
window.display();
}
getwchar();
return 0;
}
Also, during the debugging of the program, a bunch of random ASCII characters get outputted onto the console (sometimes even personal files like essays, etc...). Then, the console goes blank (null characters) and the exception is thrown.
Once, I was able to pause the program and scroll all the way up at it said something like: "Unable to open file 'chessboard.gif (with some random ASCII characters in the word)'" and then the long list of ASCII characters.
Is there something wrong with SFML or am I doing something wrong? I know that SFML docs say that sometimes the file may not load and throw a exception, but in this case, it's going crazy. Also, I have randomly put a filename that does not exist and the same thing still occurred instead of throwing a file not found exception.
I have tried the same code on Orwell Dev-C++ and it just returns a white box where the image is supposed to be and returns an exception when the file does not exist.
Some pictures:
http://i.stack.imgur.com/gq420.png
http://i.stack.imgur.com/Os8jw.png
I will be glad to provide any extra information.
Thank you,
Usandfriends!
This issue arises when you're mixing debug libraries with release mode or release libraries with debug mode. Make sure to only use -d suffixed SFML libraries when in debug mode and non suffixed SFML libraries when in release mode - as stated in the official tutorial.
As a side note, it's also recommended to always use int main(). If you just want a window without the command prompt, then you can change the subsystem to window and link against sfml-main.
I am using OpenCV 2.4.6, and trying to generate some histograms. The original example code took an image from local storage, but I modified it to use a VideoCapture object. When the code gets to cv::split(), it brings an unhandled exception. It prompts this:
"Unhandled exception at 0x5465B3D9 (opencv_core246.dll) in
visionProject.exe: 0xC0000005: Access violation writing location
0x1800E633."
The code I have is this:
VideoCapture camera;
camera.open(0);
camera >> src;
if( !src.data )
{ return -1; }
/// Separate the image in 3 places ( B, G and R )
vector <Mat> bgr_planes;
split(src, bgr_planes );
Thanks for your time.
Thanks to assistance from a friend, I was able to make it work. In order for OpenCV to work correctly, I have to set the build to Release in Visual Studio. This way, it works as it should.
I'm working on a simple background subtraction program by using OpenCV BackgroundSubtractorMOG2. The codes:
int main()
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat frame,foreground,image,edges;
BackgroundSubtractorMOG2 mog;
namedWindow("Capture", CV_WINDOW_AUTOSIZE);
namedWindow("Contours", CV_WINDOW_AUTOSIZE);
while(1)
{
cap >> frame; // get a new frame from camera
if( frame.empty() )
break;
image=frame.clone();
mog(frame,foreground,-1);
threshold(foreground,foreground,1,250,THRESH_BINARY);
medianBlur(foreground,foreground,9);
erode(foreground,foreground,Mat());
dilate(foreground,foreground,Mat());
imshow( "Capture",image );
imshow("Contours",foreground);
if(waitKey(30) >= 0) break;
}
}
The program works but upon exiting, an error will occur like this:Unhandled exception at 0xfeeefeee in {prog_name}.exe: 0xC0000005: Access violation reading location 0xfeeefeee. and it will point to crtexe.c on line 568:
if (has_cctor == 0)
_cexit();
Any idea what causes the problem? Thanks in advance.
PS: Currently using OpenCV 2.3.4 and VS C++ 2010 Exp. on Windows XP.
PSS: AFAIK each class/pointer including camera will be deinitialized/destroyed upon exit. Correct me if I wrong.
Updates(1): Still got the error, even after adding some lines into it.
Updates(2): Tried DEBUG for every line, still got nothing. Tried delete function to release resources but cannot find any pointer to use it with delete.
Updates(3): It seems like every video processing program I made using OpenCV C++ will crash on exit, even the one I copy-pasted from books/internet. Changed break with return -1, still crashes...
Updates(4): I tried my program on another PC (Ms VS 2010 Pro, Windows Vista 64b) and guess what, NO crash. Definitely something wrong with my computer's setup...
I'm currently suffering from some strange exceptions that are most probably due to me doing something incorrectly while interacting with opencv:
First-chance exception at 0x7580b9bc in xxx.exe: Microsoft C++ exception: cv::Exception at memory location 0x00c1c624..
I've already enabled the Thrown field in the Debug -> Exceptions menu, however I really can't figure out where in my code the exception is thrown.
How can I debug this?
EDIT
the stack frame reads like this (my app won't even show up in the list!):
KernelBase.dll!7580b8bc()
[Frames below may be incorrect or missing ]
KernelBase.dll!7580b8bc()
opencv_core242d.dll!54eb60cc()
You could wrap your entire main in a try catch block which prints out the exception details. If the open CV API can throw exceptions, you will need to think about handling them anyway as part of your design:
try
{
// ... Contents of your main
}
catch ( cv::Exception & e )
{
cerr << e.msg << endl; // output exception message
}
OpenCV has this handy function called cv::setBreakOnError
If you put the following into your main before any opencv calls:
cv::setBreakOnError(true);
then your program will crash, because OpenCV will do an invalid operation (dereferencing a null pointer) just before it would throw cv::Exception normally. If you run your code in a debugger, it will stop at this illegal operation, and you can see the whole call stack with all of your codes and variables at the time of the error.
I´ve got this problem by using OpenCV with WebCam. The problem in my case is that the program is trying to read an image when the Cam hasn't been initialized.
my error code:
// open camera
capture.open(0);
while (1){
//store image to matrix // here is the bug
capture.read(cameraFeed);
The solution
// open camera
capture.open(0);
while (1){
//this line makes the program wait for an image
while (!capture.read(cameraFeed));
//store image to matrix
capture.read(cameraFeed);
(sorry about my english)
Thanks