我找到了一种方法来做到这一点,但它非常重并且使一切变得滞后(主要是因为我正在逐像素地重新创建垫子)。
for (let x = 0; x < src.cols; x++) {
for (let y = 0; y < src.rows; y++) {
for (let c = 0; c < 4; c++) {
if(c != 3){
if((src.data[y * src.cols * src.channels() + x * src.channels() + c]+lum_val) < 255){
dst.data[y * dst.cols * dst.channels() + x * dst.channels() + c] = (src.data[y * src.cols * src.channels() + x * src.channels() + c]+lum_val);
}else{
dst.data[y * dst.cols * dst.channels() + x * dst.channels() + c] = 255;
}
}else{
dst.data[y * dst.cols * dst.channels() + x * dst.channels() + c] = (src.data[y * src.cols * src.channels() + x * src.channels() + c]);
}
}
}
}
是否有一个函数可以更有效地完成同样的事情?或者也许有一种更简单的方法可以得到相同的结果?
最佳答案
关注OpenCV Tutorial: Changing the contrast and brightness of an image!即可
convertScaleAbs(src, dst, alpha, beta)
Scales, calculates absolute values, and converts the result to 8-bit.
On each element of the input array, the function convertScaleAbs performs three operations sequentially: scaling, taking an absolute value, conversion to an unsigned 8-bit type
Parameters:
src input array
dst output array
alpha optional scale factor
beta optional delta added to the scaled values
关于javascript - 如何使用 OpenCV.js 增加亮度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55277921/