title: Train Cascade Object Detector bounding box out of bound?
body: <p>I am trying to train a cascade object detector using the built-in function in Matlab (vision toolbox). However, the following message came up after running the command.</p>
  
  <p>*</p>
  
  <pre><code>Error using trainCascadeObjectDetector (line 245)
  Error reading instance 1 from image 2, bounding box possibly out of image bounds.
  </code></pre>
  
  <p>*</p>
  
  <p>I don't understand why the bounding box can be out of bounds. All the parameters for my positive images are set up correctly (starting point x,y, width, and height. I used <code>createMask(h)</code> to create a mask and find the minimum coordinates for x and y to be starting point and max-min for each dimension to be the width and height), and the negative images (as far as I know) are just images without any setup needed.</p>
  
  <p>Anyone ever ran into the same problem? How did you solve it?</p>
  
  <p>EDIT:
  Here's the code. I don't have the toolbox for training the "data" struct, so I wrote one myself</p>
  
  <pre><code>positive_samples=struct;
  list=dir('my_folder_name_which_I_took_out');
  
  L=length(list)-3; %Set L to be the length of the image list.
  for i=1:length(list)
      positive_samples(i).imageFilename=list(i).name;
  end
  positive_samples(:,1)=[]; %first 3 lines do not contain file names
  positive_samples(:,1)=[];
  positive_samples(:,1)=[];
  
  for j=1:1
      imshow(positive_samples(j).imageFilename);
      title(positive_samples(j).imageFilename);
      h=imrect;
      h1=createMask(h);
      I=imread(positive_samples(j).imageFilename);
      [le, wi, hi]=size(I);
      tempmat=[];
      count=1;
      for l=1:le
          for m=1:wi
              if h1(l,m)==1
                  tempmat(count,1)=l;
                  tempmat(count,2)=m;
                  count=count+1;
              end
          end
      end
      positive_samples(j).objectBoundingBoxes(1,1)=min(tempmat(:,1));
      positive_samples(j).objectBoundingBoxes(1,2)=min(tempmat(:,2));
      positive_samples(j).objectBoundingBoxes(1,3)=max(tempmat(:,2))-min(tempmat(:,2));
      positive_samples(j).objectBoundingBoxes(1,4)=max(tempmat(:,1))-min(tempmat(:,1));
      imtool close all
  end
  trainCascadeObjectDetector('animalfinder.xml', positive_samples, 'my_neative_folder_name', 'FalseAlarmRate', 0.2, 'NumCascadeStages', 3);
  </code></pre>
  
  <p>sorry if it's messy......</p>