title: OpenCv 2.3 C - How to isolate object inside image
body: <p>i have an image like: </p>
  
  <p><img src="https://i.stack.imgur.com/LiAX7.png" alt="source"></p>
  
  <p>i want to remove the black rows and cols round the number. 
  So i want that the result is:</p>
  
  <p><img src="https://i.stack.imgur.com/6iO6U.png" alt="output"></p>
  
  <p>i try this:</p>
  
  <pre><code>void findX(IplImage* imgSrc,int* min, int* max){
      int i;
      int minFound=0;
      CvMat data;
      CvScalar maxVal=cvRealScalar(imgSrc-&gt;width * 255);
      CvScalar val=cvRealScalar(0);
      //For each col sum, if sum &lt; width*255 then we find the min
      //then continue to end to search the max, if sum&lt; width*255 then is new max
      for (i=0; i&lt; imgSrc-&gt;width; i++){
          cvGetCol(imgSrc, &amp;data, i);
          val= cvSum(&amp;data);
          if(val.val[0] &lt; maxVal.val[0]){
              *max= i;
              if(!minFound){
                  *min= i;
                  minFound= 1;
              }
          }
      }
  }
  
  void findY(IplImage* imgSrc,int* min, int* max){
      int i;
      int minFound=0;
      CvMat data;
      CvScalar maxVal=cvRealScalar(imgSrc-&gt;width * 255);
      CvScalar val=cvRealScalar(0);
      //For each col sum, if sum &lt; width*255 then we find the min
      //then continue to end to search the max, if sum&lt; width*255 then is new max
      for (i=0; i&lt; imgSrc-&gt;height; i++){
          cvGetRow(imgSrc, &amp;data, i);
          val= cvSum(&amp;data);
          if(val.val[0] &lt; maxVal.val[0]){
              *max=i;
              if(!minFound){
                  *min= i;
                  minFound= 1;
              }
          }
      }
  }
  CvRect findBB(IplImage* imgSrc){
      CvRect aux;
      int xmin, xmax, ymin, ymax;
      xmin=xmax=ymin=ymax=0;
  
      findX(imgSrc, &amp;xmin, &amp;xmax);
      findY(imgSrc, &amp;ymin, &amp;ymax);
  
      aux=cvRect(xmin, ymin, xmax-xmin, ymax-ymin);
  
      //printf("BB: %d,%d - %d,%d\n", aux.x, aux.y, aux.width, aux.height);
  
      return aux;
  
  }
  </code></pre>
  
  <p>So i use:</p>
  
  <pre><code>IplImage *my_image = cvLoad....
  CvRect bb = findBB(my_image);
  IplImage *new_image = cvCreateImage(cvSize(bb.width,bb.height), my_image-&gt;depth, 1);
  cvShowImage("test",new_image);
  </code></pre>
  
  <p>it doesn't work good, cause i try to check if in new image there are black rows or cols and they are present. what can i do? can someone help me? (sorry for my english!)</p>