Ask Your Question
-1

Access Violation with imread

asked 2013-03-14 10:54:40 -0600

NeVrOzAy gravatar image

updated 2013-03-15 04:13:44 -0600

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 ... (more)

edit retag flag offensive close merge delete

Comments

1

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!

berak gravatar imageberak ( 2013-03-14 13:49:04 -0600 )edit

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

NeVrOzAy gravatar imageNeVrOzAy ( 2013-03-15 03:51:56 -0600 )edit
1

"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.

berak gravatar imageberak ( 2013-03-15 04:26:02 -0600 )edit

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 =)

NeVrOzAy gravatar imageNeVrOzAy ( 2013-03-15 05:09:28 -0600 )edit

happy end to a long story ;)

berak gravatar imageberak ( 2013-03-15 05:22:52 -0600 )edit

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?

Kinimod gravatar imageKinimod ( 2015-02-03 12:48:57 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2013-03-14 15:28:02 -0600

You are writing the image to the relative path and reading the image from an explicit path. Some development environments actually create seperate debug folders, like visual studio, resulting in another relative location, combined to the source code. Do your cvSaveImage to the exact path of your imwrite.

BTW, why use C -style for reading and C++ - style for writing? Just use imread in stead of cvSaveImage. It could be that there are dangling pointers screwing up your code.

edit flag offensive delete link more

Comments

Could you post the following stuff

  • operating system x32 or x64

  • development environment

  • your linker options (which libraries do you include)

  • the version of openCV you have installed

Go to this tutorial, and see if you using the exact same steps to open your video file : http://docs.opencv.org/doc/tutorials/highgui/video-write/video-write.html#videowritehighgui

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-15 03:46:48 -0600 )edit

Also, you are using a lot of includes that actually do nothing specific for your code. Could you reduce the includes to simply these rules:

  • include "opencv2/highgui/highgui.hpp"

  • include "opencv2/imgproc/imgproc.hpp"

  • include "opencv2/opencv.hpp"

And start first by opening solely the video. Remove all the other code from your project and go step by step to solve this.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-15 03:50:55 -0600 )edit

finally found that my debug mode wasn't configured properly, I'm so happy that it works now, and I'm sorry for that question which have indeed a quite simple solution xD and thanks a lot for your help =) This topic is now closed I guess =)

NeVrOzAy gravatar imageNeVrOzAy ( 2013-03-15 05:12:24 -0600 )edit

Ok good for you. If you want to let people know it is solved, than accept an answer. It will show solved on the main page than.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-15 05:18:41 -0600 )edit

done ;) thank you ! =)

NeVrOzAy gravatar imageNeVrOzAy ( 2013-03-15 05:20:59 -0600 )edit

Question Tools

Stats

Asked: 2013-03-14 10:54:40 -0600

Seen: 7,651 times

Last updated: Mar 15 '13