I have been working on an image recognition program for a while now, but suddenly I noticed that when I test my program for a longer amount of time the function cvLoadImage stops returning an image sometimes. I see no clear pattern or time this occurs, but after it fails once it will keep failing for the rest of the program untill I restart again. The piece of code only runs once in a while to update my user interface.
My code:
IplImage* UIframe = cvLoadImage("../images/background.jpg", CV_LOAD_IMAGE_COLOR);
if(UIframe) {
//do stuff
} else {
cout<<"Image not loaded"<<endl;
}
cvReleaseImage(&UIframe);
There are a couple of reasons I already found for cvLoadImage failing that I checked:
- The path is static and is working earlier on in the program so the file is there
- I release the image and there are no other memory leaks to cause this
- The .jpg is not being updated while trying to load it
- I have all the right libraries installed as cvLoadImage is working earlier on
One solution is to only load the image once and keep updating it from memory, but I'd like to find out why this is happening and how to fix this.