OpenCV获取和设置图像的平均亮度

获取:

double get_avg_gray(IplImage *img)
{
    IplImage *gray = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
    cvCvtColor(img,gray,CV_RGB2GRAY);
    CvScalar scalar = cvAvg(gray);
    cvReleaseImage(&gray);
    return scalar.val[0];
}
设置:
void set_avg_gray(IplImage *img,IplImage *out,double avg_gray)
{
	double prev_avg_gray = get_avg_gray(img);
	cvConvertScale(img,out,avg_gray/prev_avg_gray);
}


你可能感兴趣的:(OpenCV)