theothergrantdavidson / opencv-ts

A place for the typescript bindings for OpencvJS
Apache License 2.0
51 stars 18 forks source link

How to imread an image from a file? #35

Open ocoleman-cordel opened 2 years ago

ocoleman-cordel commented 2 years ago

Not sure what I'm missing here, but I can't seem to use cv.imread to read a file. This is on the server side, not in the browser.

Initially I tried passing a path to a file. Then looking more closely it looks like I need to pass a HTMLImageElement or HTMLCanvasElement.

Being on the server not sure how to provide either of these. I tried using node-canvas:

import cv from 'opencv-ts';
import { createCanvas, loadImage } from'canvas'

  const canvas = createCanvas(200, 200)
  canvas.getContext('2d').drawImage(
    await loadImage(filepath), 0, 0
  )
  const referenceImage = cv.imread(canvas)

But got the below error

W20220819-06:12:50.979(0)? (STDERR) # Fatal error in , line 0
W20220819-06:12:50.979(0)? (STDERR) # archived threads in combination with wasm not supported
W20220819-06:12:50.979(0)? (STDERR) #
W20220819-06:12:50.980(0)? (STDERR) #
W20220819-06:12:50.980(0)? (STDERR) #
W20220819-06:12:50.980(0)? (STDERR) #FailureMessage Object: 0x7f7983694de0
W20220819-06:12:50.980(0)? (STDERR)  1: 0xaa8321  [/home/axldm/.meteor/packages/meteor-tool/.2.7.1.1wx46xz.ynsm++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node]
W20220819-06:12:50.980(0)? (STDERR)  2: 0x1a46f04 V8_Fatal(char const*, ...) [/home/axldm/.meteor/packages/meteor-tool/.2.7.1.1wx46xz.ynsm++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node]
W20220819-06:12:50.980(0)? (STDERR)  3: 0x12075a0  [/home/axldm/.meteor/packages/meteor-tool/.2.7.1.1wx46xz.ynsm++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node]
W20220819-06:12:50.981(0)? (STDERR)  4: 0xd2f653 v8::internal::ThreadManager::IterateArchivedThreads(v8::internal::ThreadVisitor*) [/home/axldm/.meteor/packages/meteor-tool/.2.7.1.1wx46xz.ynsm++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node]
W20220819-06:12:50.981(0)? (STDERR)  5: 0x1212922 v8::internal::wasm::WasmEngine::ReportLiveCodeFromStackForGC(v8::internal::Isolate*) [/home/axldm/.meteor/packages/meteor-tool/.2.7.1.1wx46xz.ynsm++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node]
W20220819-06:12:50.982(0)? (STDERR)  6: 0xd2de78 v8::internal::StackGuard::HandleInterrupts() [/home/axldm/.meteor/packages/meteor-tool/.2.7.1.1wx46xz.ynsm++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node]
W20220819-06:12:50.982(0)? (STDERR)  7: 0x109f663 v8::internal::Runtime_StackGuard(int, unsigned long*, v8::internal::Isolate*) [/home/axldm/.meteor/packages/meteor-tool/.2.7.1.1wx46xz.ynsm++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node]
W20220819-06:12:50.983(0)? (STDERR)  8: 0x1448e19  [/home/axldm/.meteor/packages/meteor-tool/.2.7.1.1wx46xz.ynsm++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node]
ocoleman-cordel commented 2 years ago

Did some more digging, looks like this is a limitation with the framework I'm using (Meteor). To use the opencv bindings requires WASM? And it seems Meteor does not: https://github.com/meteor/meteor/issues/11143