今天找到了一個OpenCV簡單亮度校正功能的方法感覺效果還可以,使用於簡單背景,代碼如下
int _tmain(int argc, _TCHAR* argv[])
{
IplImage* src;
// 第一條命令行參數確定了圖像的文件名。
char* filename = (char*)"C:\\Users\\chenchao\\Desktop\\結晶\\25.bmp";
if( (src = cvLoadImage( filename, 0)) == 0 )
return -1;
cvNamedWindow( "src", 1 );
cvShowImage( "src", src );
IplImage* mean=cvCreateImage(cvGetSize(src), 8, 1 );
IplImage* dst=cvCreateImage(cvGetSize(src), 8, 1 );
cvSmooth( src, mean, CV_MEDIAN , 101, 101, 0, 0 );
cvNamedWindow( "mean", 1 );
cvShowImage( "mean", mean );
int i,j;
int k;
double val,val_mean,val_dst;
float factor=0.7;
int step_src=src->widthStep/sizeof(uchar);
int step_mean=mean->widthStep/sizeof(uchar);
for(j=0;j<src->height;j++)
{
for(i=0;i<src->width;i++)
{
k=j*step_src+i;
val=((uchar*)(src->imageData))[k]; //獲取源圖像像素點數據
val_mean=((uchar*)(mean->imageData))[k];//獲取平滑處理後的圖像像素點
val_dst=(int)( (127-val_mean)*factor + val ); //計算目標像素值
//防止數據越界
if(val_dst<0)
val_dst=0;
//轉換成整數復制
((uchar*)(dst->imageData))[k]=(int)val_dst;
}
}
cvNamedWindow( "dst", 1 );
cvShowImage( "dst", dst );
cvWaitKey(0);
cvSaveImage("C:\\Users\\chenchao\\Desktop\\1.bmp",dst);
cvReleaseImage(&src);
cvReleaseImage(&mean);
cvReleaseImage(&dst);
cvDestroyWindow("src");
cvDestroyWindow("mean");
cvDestroyWindow("dst");
return 0;
}
OpenCV 利用滾動條調整圖像亮度 http://www.linuxidc.com/Linux/2012-03/56796.htm
--------------------------------------分割線 --------------------------------------
Ubuntu Linux下安裝OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm
Ubuntu 12.04 安裝 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm
CentOS下OpenCV無法讀取視頻文件 http://www.linuxidc.com/Linux/2011-07/39295.htm
Ubuntu 12.04下安裝OpenCV 2.4.5總結 http://www.linuxidc.com/Linux/2013-06/86704.htm
Ubuntu 10.04中安裝OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm
基於QT和OpenCV的人臉識別系統 http://www.linuxidc.com/Linux/2011-11/47806.htm
--------------------------------------分割線 --------------------------------------
OpenCV的詳細介紹:請點這裡
OpenCV的下載地址:請點這裡