执行后未处理的异常

时间:2011-01-08 23:39:51

标签: c++ visual-studio-2010 opencv

我正在尝试使灰色图像更加明亮,代码确实正常编译但是在seconde图片中没有变化,并且在执行完成之后出现错误消息Unhandled exception ...。这是我的一段代码:

int main(int argc, _TCHAR* argv[])
{
    IplImage *img = cvLoadImage("mra.jpg");
    if (!img) {
        printf("Error: Couldn't open the image file.\n");
        return 1;
    }
    //IplImage* new_image = getlargersize(img);

    double Min , Max ;
    Min = Max = 0 ;
    Max_Min (img , &Min , &Max);
    cout<<"the max value in the picture is :"<<Min<<" and the minimum value is :"<<Max<<endl ;

    IplImage* img2 = eclaircir(Min ,Max ,img);

    cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("Image2:", CV_WINDOW_AUTOSIZE);
    cvShowImage("Image2:", img2);
    cvShowImage("Image:", img);

    cvWaitKey(0);

    cvDestroyWindow("Image2:");
    cvDestroyWindow("Image:");
    cvReleaseImage(&img2);
    cvReleaseImage(&img);
    return 0;
}    
void Max_Min(IplImage* temp , double *min , double *max ){
    CvScalar pix ; 
    for (int i = 0 ; i < temp->height ; i++){
        for (int j = 0 ; j < temp->width ; j++){
            pix = cvGet2D(temp , i , j); 
            if ( pix.val[0] >= *max ){
                *max = pix.val[0];
            }
            if ( pix.val[0] <= *min){
            *min = pix.val[0];
            }
        }
    }
}

IplImage* eclaircir (double min , double max , IplImage* image){
    double temp = max - min ;
    CvScalar pix ;
    for (int i = 0 ; i < image->height ; i++){
        for (int j = 0 ; j < image->width ; j++){
            pix = cvGet2D(image , i , j); 
            pix.val[0] = ( pix.val[0] - min)*255 ;
            pix.val[0] = pix.val[0]/temp ;
            cvSet2D(image , i , j , pix );
        }
    }
    return image ;
}

1 个答案:

答案 0 :(得分:2)