TechStark / opencv-js

OpenCV JavaScript version for node.js or browser
https://npmjs.com/@techstark/opencv-js
Apache License 2.0
409 stars 36 forks source link

cv.matFromImageData(); returning a empty Mat{} #49

Closed ghost closed 9 months ago

ghost commented 9 months ago

i got an Error: 6931288, and when i console mat the mat is empty here is my code

static async changeAndSaveClarity(
    inputImagePath: string,
    outputImagePath: string,
    value: number
  ) {
    if (value < -100 || value > 100) {
      throw new Error("Exposure value must be between -100 and 100");
    }
    value;
    try {
      // Read the input image using Jimp
      value /= 200;
      const image = await Jimp.read(inputImagePath);
      const { data, width, height } = image.bitmap;
      const imageData = new ImageData(
        new Uint8ClampedArray(data),
        width,
        height
      );
      console.log(imageData)
      let src = cv.matFromImageData(imageData);
      console.log(src);
      let clahe = new cv.CLAHE();
      let labImage = new cv.Mat();
      cv.cvtColor(src, labImage, cv.COLOR_BGR2Lab);
      let clahed = new cv.Mat();
      clahe.apply(labImage, clahed);
      let bgr = new cv.Mat();
      cv.cvtColor(clahed, bgr, cv.COLOR_Lab2BGR);
      let dst = new cv.Mat();
      cv.addWeighted(src, 1 - value, bgr, value, 0, dst);
      new Jimp({
        width: dst.cols,
        height: dst.rows,
        data: Buffer.from(dst.data),
      }).write(outputImagePath);
    } catch (error) {
      console.error("Error:", error);
    }
  }