2 u011681047 u011681047 于 2013.08.13 11:49 提问

使用opencv切割小視窗進行SIFT運算時找不到釋放Image的位置

我想要將圖片導入並且進行切割成小方塊(約16塊)後進行SIFT運算的方式得到特徵數據
當我想要把配置給切出的小塊圖形的Image空間釋放時卻找不到一個正確的位置
似乎是第一張圖片的最後一張圖片運算完畢時他已配置相同名稱的記憶體給下一張圖片的第一個小方塊
如果無法釋放這個資源我將不能對大量的圖片進行運算了
麻煩各位幫我看一下我的問題該如何解決...>_<

IplImage* SRC = NULL;   
IplImage* image1 = NULL;   
IplImage* grey_im1 = NULL;   
IplImage* DoubleSizeImage = NULL;  
IplImage* tempSRC=NULL;
IplImage *src=NULL;

CvMat *mat_roi;
CvRect rect_roi;

CvMat* image1Mat = NULL;  
CvMat* tempMat=NULL;  

ImageOctaves *Gaussianpyr;  

#define Im1Mat(ROW,COL) ((float *)(image1Mat->data.fl + image1Mat->step/sizeof(float) *(ROW)))[(COL)]  

#define Im1B(ROW,COL) ((uchar*)(image1->imageData + image1->widthStep*(ROW)))[(COL)*3]  
#define Im1G(ROW,COL) ((uchar*)(image1->imageData + image1->widthStep*(ROW)))[(COL)*3+1]  
#define Im1R(ROW,COL) ((uchar*)(image1->imageData + image1->widthStep*(ROW)))[(COL)*3+2]  

storage = cvCreateMemStorage(0); 

//讀取圖片  
const char *filenameTemp=filename;
if ( (SRC = cvLoadImage(filenameTemp, 1)) == 0 )   // test1.jpg einstein.pgm back1.bmp  
    return  -1; 
//cvReleaseImage(&src);
//寬/高   
double height=cvGetDimSize(SRC,0);
double width=cvGetDimSize(SRC,1);
double temp_x=0,temp_y=0;
int divide_x=width/4,divide_y=height/4;
int Div_x[4],Div_y[4];
Div_x[0]=0;Div_y[0]=0;
for(int i=1;i<4;i++)
{
    temp_x+=divide_x;
    temp_y+=divide_y;
    Div_x[i]=temp_x;
    Div_y[i]=temp_y;
    cout << Div_x[i] << " " << Div_y[i] << endl;
}

int dst_w = 160, dst_h =120;//目標ROI影像大小
//CvSize size = cvSize(dst_w, dst_h);//取得影像大小
//src = cvCreateImage( size, IPL_DEPTH_8U, 3);

for(int i=0;i<4;i++)
{   
    tempSRC=cvCloneImage(SRC);
    for(int j=0;j<4;j++)
    {                   
        mat_roi = cvCreateMat(dst_h, dst_w,CV_8UC3);
        cout << Div_x[i] << " " << Div_y[j] << endl;
        //cvRect(X, Y, 寬, 高)
        rect_roi = cvRect(Div_x[i], Div_y[j], dst_w, dst_h);
        //從SRC影像中切割rect_roi位置和大小儲存在mat_roi陣列
        cvGetSubRect(tempSRC, mat_roi, rect_roi);
        //cvGetImage(陣列mat, 影像image),將陣列轉成影像
        cvGetImage(mat_roi, src);

        grey_im1 = cvCreateImage(cvSize(src->width, src->height), IPL_DEPTH_8U,1);  
        DoubleSizeImage = cvCreateImage(cvSize(2*(src->width), 2*(src->height)), IPL_DEPTH_8U,3);  

        //圖像陣列
        image1Mat = cvCreateMat(src->height, src->width, CV_32FC1);  

        cvCvtColor(src, grey_im1, CV_BGR2GRAY);  
        cvConvert(grey_im1, image1Mat);  
        cvConvertScale( image1Mat, image1Mat, 1.0/255, 0 );  


        int  dim = min(image1Mat->rows, image1Mat->cols);  
        numoctaves = ( int ) (log(( double ) dim) / log(2.0)) - 2;
        numoctaves = min(numoctaves, MAXOCTAVES);  

        //Step1
        tempMat = ScaleInitImage(image1Mat) ;  
        //Step2
        Gaussianpyr = BuildGaussianOctaves(tempMat) ;  
        //Step3
        int  keycount=DetectKeypoint(numoctaves, Gaussianpyr);  
        cout << "The number of keypoints is" << keycount << endl;

        //釋放資源
        cvReleaseMat(&image1Mat);
        cvReleaseImage(&grey_im1);
        cvReleaseImage(&DoubleSizeImage);
        cvSet(src,cvScalar(0,0,0));
    }   
    cvReleaseImage(&tempSRC);
}
cvReleaseMat(&mat_roi);
cvReleaseImage(&SRC);
cvReleaseMemStorage( &storage);
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!