作者:big tiger qq:517725908
以下程序首先读取摄像头的视频,然后转换到yuv空间,对Y进行直方图均衡化,在变回rgb空间,
int main( int argc, char** argv )
{
IplImage* eqlimage = NULL;
IplImage* yuvimage =NULL;
;
IplImage* yImage =NULL;
IplImage* uImage =NULL;
IplImage* vImage =NULL;
IplImage* pFrame =NULL;
CvCapture* pCapture =NULL;
int nFrmNum = 0;
cvNamedWindow("src",1);
cvNamedWindow("dst",2);
pCapture = cvCreateCameraCapture(-1);
while (1)
{
pFrame = cvQueryFrame(pCapture);
nFrmNum++;
if(1==nFrmNum)
{
eqlimage = cvCreateImage(cvGetSize(pFrame),pFrame->depth,3);
yuvimage = cvCreateImage(cvGetSize(pFrame),pFrame->depth,3);
yImage =cvCreateImage(cvGetSize(pFrame),pFrame->depth,1);
uImage = cvCreateImage(cvGetSize(pFrame),pFrame->depth,1);
vImage = cvCreateImage(cvGetSize(pFrame),pFrame->depth,1);
}
cvCvtColor(pFrame,yuvimage,CV_BGR2YCrCb);
cvSplit(yuvimage, yImage,uImage,vImage,NULL);
cvEqualizeHist(yImage,yImage);
cvMerge(yImage,uImage,vImage,NULL,yuvimage);
cvCvtColor(yuvimage,eqlimage,CV_YCrCb2BGR);
cvShowImage("src",pFrame);
cvShowImage("dst",eqlimage);
if(cvWaitKey(37) == 27)
{
break;
}
}
cvDestroyWindow("src");
cvDestroyWindow("dst");
cvReleaseImage(&yImage);
cvReleaseImage(&uImage);
cvReleaseImage(&vImage);
cvReleaseImage(&yuvimage);
cvReleaseImage(&eqlimage);
cvReleaseCapture(&pCapture);
return 0;
}