Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I think I solved my problem. In the code below, I kept reassigning the Mat variable image while looping through sub-directories of images.

Mat image;
for(directory_iterator di(dirPath); di != directory_iterator(); di++)
{
  // read in file
  if(is_directory(di->path()))
  {
    for(directory_iterator j(di->path()); j != directory_iterator(); j++)
    {
      image = imread(j->path().c_str(), CV_LOAD_IMAGE_COLOR);
   ...

When I declared image in the innermost for-loop, I stopped having problems. Can anyone explain why reassigning image multiple times would eventually cause memory problems?

click to hide/show revision 2
added getMask call in innermost for-loop

I think I solved my problem. In the code below, I kept reassigning the Mat variable image while looping through sub-directories of images.

Mat image;
for(directory_iterator di(dirPath); di != directory_iterator(); di++)
{
  // read in file
  if(is_directory(di->path()))
  {
    for(directory_iterator j(di->path()); j != directory_iterator(); j++)
    {
      image = imread(j->path().c_str(), CV_LOAD_IMAGE_COLOR);
   ...
      Mat maskImage = getMask(image);
   ...

When I declared image in the innermost for-loop, I stopped having problems. Can anyone explain why reassigning image multiple times would eventually cause memory problems?