Learning‎ > ‎

OpenCV

Transforming the Image - cvPyrDown()

cvPyrDown is a wrapper image that allocates the output image and perform transformations we want.
  • Performs a gaussian smooth. Use it for reducing an image by a factor of 2
source:
IplImage* doPyrDown(IplImage* in, int filter = IPL_GAUSSIAN_5x5){
   //make sure image is divisible by two
   assert(in->width%2==0 && in->height%2==0);

   IplImage* out = cvCreateImage(
      cvSize(in->width/2, in->height/2),
      in->depth,
      in->nChannels);
   cvPyrDown(in, out);
   return(out);
}

int main(int argc, char** argv)

{
   //from the camera
   CvCapture* capture = cvCreateCameraCapture(0);
   //from a video file
   //cvCreateFileCapture(...);
   assert(capture != NULL);

   //rest of program
   cvNamedWindow("Webcam", CV_WINDOW_AUTOSIZE);
   cvNamedWindow("Modified", CV_WINDOW_AUTOSIZE);

   IplImage* frame;
   IplImage* mod;
 
   while(1)
   {
      frame = cvQueryFrame(capture);
      if(!frame) break;
      mod = doPyrDown(frame);
      cvShowImage("Webcam", frame);
      cvShowImage("Modified", mod);
      cvReleaseImage(&mod);
      char c = cvWaitKey(37);
      if(c == 27) break;
   }
   cvReleaseCapture(&capture);
   cvDestroyWindow("Webcam");
   cvDestroyWindow("Modified");
}

output:

Canny Edge Detection


Comments