79513490

Date: 2025-03-17 01:32:59
Score: 0.5
Natty:
Report link

Figured out the problem.

I had previous only used jscanify in the browser, and I didn't realize its API is different for Node.js.

In the browser, I include OpenCV through CDN. On the server I thought using the opencv package was enough but that wasn't the case.

Calling loadOpenCV before doing anything else fixes the issue:

processor.loadOpenCV((opencv) => { // <-- this line
  loadImage('images/test.png').then((originalImage) => {
    const paperExtracted = processor.extractPaper(originalImage, 50, 100); // width, height
    const paperHighlighted = processor.highlightPaper(originalImage);

    const extractedBuffer = paperExtracted.toBuffer('image/jpeg');
    const highlightedBuffer = paperHighlighted.toBuffer('image/jpeg');

    fileSystem.writeFileSync('images/test-extracted.png', extractedBuffer);
    fileSystem.writeFileSync('images/test-highlighted.png', highlightedBuffer);
  });
});
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Performant392