title: OpenCV resizing and cropping image according to pixel value
body: <pre><code>#include "iostream"
  #include "cv.h"
  #include "highgui.h"
  #include "cvaux.h"
  #include "cxmisc.h"
  #include "math.h"
  
  using namespace cv;
  using namespace std;
  
  int main(){
  
  int height, width, x, y, i, minX, minY, maxX, maxY;
  char imgFileName[100];
  
  
  IplImage *origImage = cvLoadImage("BaybayinMark/b9.jpg", -1);
  height = origImage-&gt;height;
  width = origImage-&gt;width;
  
  IplImage *grayImage = cvCreateImage(cvSize(width, height), 8, 1);
  IplImage *binImage = cvCreateImage(cvSize(width, height), 8, 1);
  
  
  //Pre-processing phase
  
  
  cvCvtColor(origImage, grayImage, CV_BGR2GRAY);
  cvDilate(grayImage, grayImage, NULL, 1);
  cvSmooth(grayImage, grayImage, CV_GAUSSIAN, 21, 21, 0, 0);
  cvThreshold(grayImage, binImage, 120, 255, CV_THRESH_BINARY);
  cvNormalize(binImage,binImage,0,1,CV_MINMAX);
  
  minX = width;
  minY = height;
  maxX = 0;
  maxY = 0;
  
  
  CvScalar s;
  
  
  for (x=0; x&lt;width-1; x++){
  for(y=0; y&lt;height-1; y++){
      s = cvGet2D(binImage, y, x);
      //printf("%f\n", s.val[0]);
      if (s.val[0] == 1){
          //printf("HELLO");
          minX = min(minX, x);
          minY = min(minY, y);
          maxX = max(maxX, x);
          maxY = max(maxY, y);
  
      }   
  }
  }
  
  cvSetImageROI(binImage, cvRect(minX, minY, maxX-minX, maxY-minY));
  
  IplImage *cropImage = cvCreateImage(cvGetSize(binImage), 8, 1);
  
  cvCopy(binImage, cropImage, NULL);
  
  cvSaveImage("crop/cropImage9.jpg", cropImage);
  cvResetImageROI(binImage);
  
  cvReleaseImage(&amp;origImage);
  cvReleaseImage(&amp;binImage);
  
  cvReleaseImage(&amp;grayImage);
  cvReleaseImage(&amp;cropImage);
  
  }
  </code></pre>
  
  <p>Hi! i just want to ask about this code. I am trying to identify the outermost edges of an image and crop the image according them. All I was having after running was a black image with the same size. Am I trying to do it the wrong way? Please enlighten me I'm a beginner with OpenCV.</p>