opencv-js icon indicating copy to clipboard operation
opencv-js copied to clipboard

error cv.LUT is not a function

Open ghost opened this issue 1 year ago • 0 comments

got an error when using cv.Lut here is my code

static async changeAndSaveExposure(
    inputImagePath: string,
    outputImagePath: string,
    value: number
  ) {
    if (value < -100 || value > 100) {
      throw new Error("Exposure value must be between -100 and 100");
    }

    try {
      const image = await Jimp.read(inputImagePath);
      const { data, width, height } = image.bitmap;
      const imageData = new ImageData(
        new Uint8ClampedArray(data),
        width,
        height
      );
      let src = cv.matFromImageData(imageData);
      const gammaTable = new Uint8Array(imageData.data.length);
    
      for (let x = 0; x < imageData.data.length; x++) {
          gammaTable[x] = Math.round(Math.pow(x / 255.0, (value * -1) + 1) * 255.0);
      }
  
      const gammaMat = cv.matFromArray(1, imageData.data.length, cv.CV_8U, gammaTable);
      const dst = new cv.Mat();
      cv.LUT(src, gammaMat, dst)
      new Jimp({
        width: dst.cols,
        height: dst.rows,
        data: Buffer.from(dst.data),
      }).write(outputImagePath);
      console.log(`Success`);
    } catch (error) {
      console.error("Error:", error);
    }
  }
  

ghost avatar Jan 04 '24 10:01 ghost