0
votes

I am trying to use opencv2, built on ubuntu 10.04 to get a simple program going which reads a exisitng image, creates another image from it and resize that original image by 2(both width and height). Below is the code. Upon execution, I don't see the resized image window.

# include "stdio.h"
#include "opencv2/highgui/highgui_c.h"
#include <opencv2/imgproc/types_c.h>

int main( int argc, char** argv ) {
  IplImage* img = 0;
  IplImage* dst_img = 0;


  if( argc < 2 ) {
    printf( "Usage: Accepts one image as argument\n" );
    exit( EXIT_SUCCESS );
  }

  img = cvLoadImage( argv[1],1);
  if( !img ) {
    printf( "Error loading image file %s\n", argv[1]);
    exit( EXIT_SUCCESS );
  }

  dst_img = cvCreateImage(cvSize(img->width*2,img->height*2),img->depth,img->nChannels);
  if( !dst_img ) {
    printf( "Error loading output image file \n");
    exit( EXIT_SUCCESS );
  }


  cvResize(img,dst_img,CV_INTER_LINEAR); 

  cvNamedWindow( "Original Image", CV_WINDOW_AUTOSIZE );
  cvNamedWindow( "RescaledImage", CV_WINDOW_AUTOSIZE );

  cvMoveWindow( "Original Image", 720, 515 );
  cvMoveWindow( "RescaledImage", 1500,1200 );

  cvShowImage( "Original Image", img );
  cvShowImage( "RescaledImage", dst_img );

  cvWaitKey( 0 );

  cvReleaseImage( &img );
  cvReleaseImage( &dst_img );

  cvDestroyWindow( "Original Image" );
  cvDestroyWindow( "RescaledImage" );

  return EXIT_SUCCESS;
  }

I am using cvCreateImage(), & cvResize() correctly above?

How can I resize the input image by 2 in both directions?

Any pointers on web(blogs,tutorials) , books for OpenCV which has lot of sample code which one can use to study opencv hands-on?

1
My bad. It works fine. Reason I was not seeing the 2nd rescaled window was:- I was running the code on Ubuntu, exported the display to a Windows Machine from where I was working(Xserver running on windows). When I checked on the ubuntu terminal and executed this code, for some strange reason, second openCV window of the scaled image was shown up way down on screem, I had to drag it up to to see it. The window displayed on my windows, did not have any possibility of dragging, as it only used to show on the task bar, but nothing was displayed even when I click on it! Strange. Any explanation.goldenmean
Now I see that you are not only creating a new image, but you are creating one that is double the size of the original. Forget what I said before. Consider adding the solution of the problem as an answer to this thread so it can help others in the future.karlphillip

1 Answers

1
votes
cvMoveWindow( "RescaledImage", 1500,1200 ); 

My mistake. I thought this was the dimension of window/image. But this is the position of the window on screen. changed it to -

cvMoveWindow( "RescaledImage", 100,100 );

Both windows are fine now!