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);
});
});