2011-01-08 61 views
-1

我试图使灰色图像更亮,代码确实编译了正常,但没有更改后台图片,并且在执行完成后显示错误消息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

要确定为什么你会得到一个异常,知道你得到了什么异常显然是有用的。此外,你应该格式化你的文章,使其可读性(编辑窗口上方有按钮,您可以点击进行格式化)。 – sth 2011-01-08 23:46:03

+1

在Visual Studio中,有一个选项可以让调试器中断异常。 – StackedCrooked 2011-01-09 00:53:26

回答

2