[英]Adjusting Brightness, OpenCV and c++
I wanted to know if there is any function of OpenCV using C++ to adjust the brightness and contrast of a video / frame. 我想知道OpenCV是否有任何使用C ++来调整视频/帧的亮度和对比度的功能。 You can convert from BGR color space to HSV color space, and discard the latter component V (luminance) to make the algorithm less sensitive to light conditions in the video, but how can I do it?
您可以将BGR色彩空间转换为HSV色彩空间,并丢弃后一个组件V(亮度),使算法对视频中的光线条件不太敏感,但我该怎么办呢?
I was thinking of using something like cvAddS (frame, cvScalar (-50, -50, -50), frame) to Decrease the brightness, cvAddS and cvScalar work's well for C but how can I do that for C++, I use AddS and Scalar in my program, but don't work with C++ 我当时正在考虑使用cvAddS(frame,cvScalar(-50,-50,-50),frame)之类的东西来降低亮度,cvAddS和cvScalar对于C来说效果很好,但是对于C ++,我该如何使用AddS和我程序中的标量,但不适用于C ++
int main() {
VideoCapture video(1);
if(!video.isOpened()) {
cerr<<"No video input"<<endl; return -1;
}
namedWindow("Video",CV_WINDOW_AUTOSIZE);
for(;;) {
Mat frame;
video >> frame; if(!frame.data) break;
Mat frame2;
//I USE AddS AND Scalar TO DECREASE THE BRIGHTNESS
AddS(frame,Scalar(-50,-50,-50),frame2);
//BUT DON'T WORK WITH C++
imshow("Video",frame2);
int c=waitKey(20);
if(c >= 0)break;
}
}
Use matrix expression : 使用矩阵表达式 :
cv::Mat frame2 = frame + cv::Scalar(-50, -50, -50);
You might also want to adjust the contrast with histogram equalization . 您可能还想通过直方图均衡来调整对比度。 Convert your RGB image to HSV and apply
cv::equalizeHist()
to the V channel. 将RGB图像转换为HSV并将
cv::equalizeHist()
应用于V通道。
Brightness and contrast are usually corrected using a linear transformation of the pixel values. 通常使用像素值的线性变换来校正亮度和对比度。 Brightness corresponds to the additive shift and contrast corresponds to a multiplicative factor.
亮度对应于加性偏移,对比度对应于乘法因子。
In general, given a pixel value v
, the new value after to correction would be v'=a*v + b
. 通常,给定像素值
v
,校正后的新值将为v'=a*v + b
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.