Access Violation with imread
Hi all !
I'm trying to use imread to open an image that I write just before, here is my code (sorry, some is in French =) ):
// essais.cpp : définit le point d'entrée pour l'application console.
#include "stdafx.h"
////////////////////////
//**Premiers essais**//
///////////////////////
#include "opencv2/opencv.hpp"
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
//**Variables
printf("Initialisation variables\n");
CvCapture *avi;
IplImage* im;
Mat immat, imthresh;
Mat imde, imcanny;
char* trackbar_value = "Valeur";
cvNamedWindow("acquisition", CV_WINDOW_AUTOSIZE );
namedWindow("binaire", CV_WINDOW_AUTOSIZE );
namedWindow("dne", CV_WINDOW_AUTOSIZE );
namedWindow("cont", CV_WINDOW_AUTOSIZE );
//**Ouverture de la video
printf("Ouverture video\n");
avi = cvCaptureFromFile("G:\\Anthias\\Output16_boncontraste_bonneglisse_toAVI.avi");
if (!avi)
{
printf("Video non ouverte");
return -1;}
//**Recuperation de la dernière image de la video
while(cvGrabFrame(avi))
im = cvQueryFrame(avi);
cvShowImage("acquisition",im);
cvSaveImage("image.jpg",im);
//**Traitement de l'image
//**Récupération de l'image en tant que Mat
printf("Traitement image\n");
printf("ouverture de l'image...");
immat = imread( "G:/Anthias/OpenCV/Essais/essais/essais/image.jpg", 1 );
if (immat.empty())
{
printf("Image non ouverte\n");
cvWaitKey();
return -2;}
else {printf("Image ouverte\n");}
imshow("binaire",immat);
cvWaitKey();
Everything works, until imread, it crashes and I've an error message :
Unhandled exception at 0x7854fdf1 (msvcr90d.dll) in essais.exe: 0xC0000005: Access
violation reading location 0xCCCCCCCC.
I've seen a question where someone had the same error, but his solution is not mine,
The problem was in environmental variable path, there was for version vs2008 and next for 2012.
I'm using opencv 2.4.1 with Visual Studio 2008, and I've nothing concerning the 2012 version in my path so... IDK xD
I suppose there is something wrong in my environment or whatever, but I can't figure out what it is, and I'm searching for sooo long now ... Please help me ! =) xD
If you need some more infos, just tell me and I'll edit ;)
Thanks all =)
EDIT 1 :
// essais.cpp : définit le point d'entrée pour l'application console.
#include "stdafx.h"
////////////////////////
//**Premiers essais**//
///////////////////////
#include "opencv2/opencv.hpp"
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <opencv2 core="" core.hpp="">
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
//**Variables
printf("Initialisation variables\n");
VideoCapture avi;
Mat im, immat;
Mat imde, imcanny, imthresh;
char* trackbar_value = "Valeur";
cvNamedWindow("acquisition", CV_WINDOW_AUTOSIZE );
namedWindow("binaire", CV_WINDOW_AUTOSIZE );
namedWindow("dne", CV_WINDOW_AUTOSIZE );
namedWindow("cont", CV_WINDOW_AUTOSIZE );
//**Ouverture de la video
printf("Ouverture video\n");
avi = VideoCapture("G:/Anthias/Output16_boncontraste_bonneglisse_toAVI.avi");
if (!avi.isOpened())
{
printf("Video non ouverte");
return -1;}
I've re-write all my code in C++, and now I've got the same kind of error, but with VideoCapture :
Unhandled exception at 0x77c17bec in essais.exe: 0xC0000005: Access
violation reading location 0xCCCCCCCC.
I think this is why I started to write using C style, and then changed to C++ style because I ...
any chance, that you're mixing stuff, that does not belong together ? like 32bit exe loading 64bit dlls ( related to the PATH environment topic above ) or debug builds with release libs, or the other way round ? 0xCCCCCCCC is uninitialized memory, and error 0xC0000005 mostly occurs when mismatching dlls / libs
sidenote: mixing the old(IplImage, cv*Functions) and the new Api(cv::Mat, namespace cv::) only increases unnessecary complexity. stick to the new one, please!
I've re-wrote my code using C++ style only, please see my edit 1 =) Now I have the same error but with VideoCapture :/ ... Plus, In Tools->Options for library files, I had a path for x64 vc9 lib, I changed for x86 vc9 lib, restart, bit still have that error ... so idk
"I've added core241.lib , highgui241.lib and imgproc241.lib" that's ok for release mode. don't forget that it's core241d.lib , highgui241d.lib and imgproc241d.lib for debug.
oh my god, finally found how to configure this debug mode, it works now !! =) no such error now, i'm so happy \o/, and I'm sorry because it was quite a simple problem/solution by the way, I just didn't managed to find a complete configuration tuto xD Thanks a lot for your idea and your help. This topic can be closed now I guess =)
happy end to a long story ;)
Hello NeVrOzAy, could you please post some more information? I have the same issue. I've read the tutorials again and again, but I have not found any solution. Do you have any link to a tutorial, which fixed your issue?