2012-02-04 160 views
0

我正在嘗試調整圖像大小,然後顯示它以檢查它是否已被調整大小。調整大小和顯示圖像

#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; 
} 

但它會產生一個錯誤 OpenCV的錯誤:斷言未知功能 文件c ==失敗dst.type < >>:\從\ winInstallerMegaPack的\ src \ OpenCV的\模塊\ imgproc的\ src \ imgwarp。 cpp line. 請指出我做錯了什麼,並提出一些解決方法。另一方面,其他代碼工作正常。

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; 

請說明。

+0

問題是,您試圖將操作的結果存儲在與原始圖像不兼容的圖像中:兩張圖像必須具有相同類型(n通道和深度)。 – karlphillip 2012-02-05 03:25:53

+0

@ karlphillip-我瞭解這兩個圖像有一些區別,但我無法弄清楚區別。謝謝。 – 2012-02-05 07:35:41

回答

1

您是使用第一個還是第二個代碼示例?

如果你使用第一個,我想你的「tmpsize」應該和你的源文件具有相同的通道數。

+0

我已經嘗試使用這兩個代碼。第一個產生了一個錯誤,但第二個完全罰款。你是什麼意思相同數量的渠道? – 2012-02-05 07:34:05

+0

由於cvResize要求你符合這個標準,所以karlphillip解釋「ipl」和「tmpsize」必須是相同的類型。因此,確保它們都具有相同的深度和頻道數量。有關更多信息,請查看OpenCV文檔:http://opencv.willowgarage.com/documentation/basic_structures.html#iplimage – dom 2012-02-05 09:41:12

0

在第一個示例中,您爲通道數量編寫0 0 所以更改 IplImage * tmpsize = cvCreateImage(size,8,0); line IplImage * tmpsize = cvCreateImage(size,ipl-> depth,ipl-> nChannels);