Abhishek kumar
Abhishek kumar

Reputation: 2676

Resizing and displaying image

I am trying to resize an image and then display it to check whether it has been resized or not.

#include"cv.h"
#include"highgui.h"
#include<iostream>
 using namespace cv;

 int main()
 {
     IplImage* ipl = cvLoadImage("test1.jpg");
     cvShowImage("original:",ipl);
     CvSize size = cvSize(128,128); 
    IplImage* tmpsize=cvCreateImage(size,8,0);   
    cvResize(ipl,tmpsize,CV_INTER_LINEAR);
    cvShowImage("new",tmpsize);

     waitKey(0);
     return 0;
 }

But it produces an error OpenCV Error:Assertion failed==dst.type<>> in unknown function file c:\slave\winInstallerMegaPack\src\opencv\modules\imgproc\src\imgwarp.cpp line 3210. Please point what am i doing wrong and suggest some way to overcome it. On the other hand other code works fine.

 IplImage *source = cvLoadImage( "test1.jpg");
// Here we retrieve a percentage value to a integer
int percent =50;
// declare a destination IplImage object with correct size, depth and channels
      IplImage *destination = cvCreateImage
( cvSize((int)((source->width*percent)/100) , (int)((source->height*percent)/100) ),
                                     source->depth, source->nChannels );

//use cvResize to resize source to a destination image
cvResize(source, destination);

// save image with a name supplied with a second argument
      cvShowImage("new:",destination);
      waitKey(0);
return 0;

Please explain.

Upvotes: 0

Views: 9010

Answers (2)

Birol Kuyumcu
Birol Kuyumcu

Reputation: 1213

in the first example you write 0 for number of channels so change IplImage* tmpsize=cvCreateImage(size,8,0); line IplImage* tmpsize=cvCreateImage(size,ipl->depth, ipl->nChannels );

Upvotes: 0

dom
dom

Reputation: 11972

Are you using the first or the second code example?

If you're using the first one, I guess your "tmpsize" should have the same number of channels as your source file.

Upvotes: 1

Related Questions