javascript - 如何使用 OpenCV.js 增加亮度?

标签 javascript opencv image-processing

找到了一种方法来做到这一点,但它非常重并且使一切变得滞后(主要是因为我正在逐像素地重新创建垫子)。

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/

相关文章:

javascript - Vue.js:在方法中使用计算属性返回未定义的错误

javascript - 使用 NodeJS 使 Discord 机器人发送带有消息的图片

javascript - 如何更改象形图的图标?

c++ - 如何使用opencv检测 dentry

java - Zxing NotFoundException

opencv - rect.contain() 没有显示正确的结果

javascript - React-native 和 VS 代码

opencv - 编译/链接 OpenCV Matlab 源文件时出错

c++ - Visual Studio 2013 链接 : fatal error LNK1181: cannot open input file

java - 对二维数组中的对象使用方法