1. 程式人生 > >OpenCV對影象的光照歸一化處理

OpenCV對影象的光照歸一化處理

  1. #include <cv.h>
  2. #include <highgui.h>
  3. #include <stdio.h>
  4. #include <string>
  5. usingnamespace std;  
  6. void main()  
  7. {  
  8.     int i;  
  9.     IplImage *pImageChannel[4] = {0,0,0,0};  
  10.     int count = 15;  
  11.     char *name = newchar;  
  12.     while(count<=17)  
  13.     {  
  14.         string FileName = "S010_001_015942"
    ;  
  15.         itoa(count,name,10);  
  16.         FileName = FileName + name;  
  17.         FileName = FileName + string(".png");  
  18.         IplImage *pSrcImage = cvLoadImage(FileName.c_str());  
  19.         IplImage *pImage = cvCreateImage(cvGetSize(pSrcImage), pSrcImage->depth, pSrcImage->nChannels);  
  20.         if(pSrcImage)  
  21.         {  
  22.             for( i=0; i<pSrcImage->nChannels; i++)  
  23.             {  
  24.                 pImageChannel[i] = cvCreateImage( cvGetSize(pSrcImage), pSrcImage->depth, 1);  
  25.             }  
  26.             // 通道分離
  27.             cvSplit( pSrcImage, pImageChannel[0], pImageChannel[1],pImageChannel[2],NULL);  
  28.             for( i = 0; i < pImage->nChannels; i++ )  
  29.             {  
  30.                 //直方圖均衡化
  31.                 cvEqualizeHist(pImageChannel[i], pImageChannel[i]);  
  32.             }  
  33.             // 通道組合
  34.             cvMerge( pImageChannel[0], pImageChannel[1], pImageChannel[2],NULL,pImage);  
  35.             // ……影象顯示程式碼(略)
  36.             // 釋放資源
  37.             for( i=0; i<pSrcImage->nChannels; i++)  
  38.             {  
  39.                 if(pImageChannel[i])  
  40.                 {  
  41.                     cvReleaseImage( &pImageChannel[i] );  
  42.                     pImageChannel[i] = 0;  
  43.                 }  
  44.             }  
  45.             cvNamedWindow("1");  
  46.             cvShowImage("1",pImage);  
  47.             cvWaitKey();  
  48.             cvDestroyWindow("1");  
  49.             //
  50.             string saveFile = ".\\002\\histgram\\";  
  51.             saveFile = saveFile + name;  
  52.             saveFile = saveFile + ".bmp";  
  53.             cvSaveImage(saveFile.c_str(),pImage);  
  54.             count++;  
  55.             cvReleaseImage( &pImage );  
  56.         }  
  57.     }  

為什麼總在cvSaveImage那個函數出現錯誤:

OpenCV提高對比度.exe 中的 0x5f9ed7af (highgui200d.dll) 處未處理的異常: 0xC0000005: 讀取位置 0xed4674bb 時發生訪問衝突

先留個檔,以後繼續處理