UrielCh / opencv4nodejs

ESM Nodejs bindings to OpenCV 3/4
MIT License
234 stars 49 forks source link

Issue with opencv4nodejs Installation and Execution #154

Closed maybeing closed 3 weeks ago

maybeing commented 4 weeks ago

Hi! I'm facing many errors while setting up opencv4nodejs in my project. These are the current ones:

Opencv4nodejs Installation: I used pnpm to install @u4/opencv4nodejs, which apparently completed successfully without any errors.

PS C:\Users\XXX\backend> pnpm list
Legend: production dependency, optional only, dev only

backend@1.0.0 C:\Users\XXX\backend

dependencies:
@u4/opencv-build 1.1.0
@u4/opencv4nodejs 7.1.0
node-gyp 10.2.0
PS C:\Users\XXX\backend>

OpenCV Installation: I also installed OpenCV using vcpkg, and it confirmed that OpenCV 4.8.0 was already installed.

PS C:\Users\XXX\backend> vcpkg install opencv
Computing installation plan...
The following packages are already installed:
    opencv[core,default-features]:x64-windows@4.8.0#1
opencv:x64-windows is already installed
Total install time: 1.03 ms
opencv provides CMake targets:

  # this is heuristically generated, and may not be correct
  find_package(OpenCV CONFIG REQUIRED)
  # note: 10 additional targets are not displayed.
  target_link_libraries(main PRIVATE opencv_ml opencv_dnn opencv_core opencv_flann)

Build: I believe I managed to build opencv:

PS C:\Users\XXX\backend> npx opencv-build-npm
2024-08-15 12:26:12 Info: config found opencv4nodejs section in %s C:\Users\XXX\backend\package.json
2024-08-15 12:26:12 Info: init no_autobuild is set.
2024-08-15 12:26:12 Info: init
2024-08-15 12:26:12 Info: applyEnvsFromPackageJson the following opencv4nodejs environment variables are set in the package.json:
2024-08-15 12:26:12 Info: applyEnvsFromPackageJson disableAutoBuild: 1
2024-08-15 12:26:12 Info: applyEnvsFromPackageJson OPENCV_INCLUDE_DIR: C:\Users\XXX\vcpkg\vcpkg\installed\x64-windows\include
2024-08-15 12:26:12 Info: applyEnvsFromPackageJson OPENCV_LIB_DIR: C:\Users\XXX\vcpkg\vcpkg\installed\x64-windows\lib
2024-08-15 12:26:12 Info: applyEnvsFromPackageJson OPENCV_BIN_DIR: C:\Users\XXX\vcpkg\vcpkg\installed\x64-windows\bin
2024-08-15 12:26:12 Info: init Workdir will be: %s C:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv-build@1.1.0\node_modules\@u4\opencv-build\esm\opencv-0.0.0-8b1ea
2024-08-15 12:26:12 Info: install OPENCV4NODEJS_DISABLE_AUTOBUILD is set skipping auto build...
2024-08-15 12:26:12 Info: install writing auto-build file into directory: %s C:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv-build@1.1.0\node_modules\@u4\opencv-build\esm\opencv-0.0.0-8b1ea\auto-build.json
2024-08-15 12:26:12 Info: install Cretate link %s to %s C:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv-build@1.1.0\node_modules\@u4\opencv-build\esm\latest C:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv-build@1.1.0\node_modules\@u4\opencv-build\esm\opencv-0.0.0-8b1ea
PS C:\Users\XXX\backend>

Running project: But when I try to run my project, I get this error:

PS C:\Users\XXX\backend> node teste.js
2024-08-15 12:27:23 Info: config found opencv4nodejs section in %s C:\Users\XXX\backend\package.json
2024-08-15 12:27:23 Info: init no_autobuild is set.
2024-08-15 12:27:23 Info: init
2024-08-15 12:27:23 Info: applyEnvsFromPackageJson the following opencv4nodejs environment variables are set in the package.json:
2024-08-15 12:27:23 Info: applyEnvsFromPackageJson disableAutoBuild: 1
2024-08-15 12:27:23 Info: applyEnvsFromPackageJson OPENCV_INCLUDE_DIR: C:\Users\XXX\vcpkg\vcpkg\installed\x64-windows\include
2024-08-15 12:27:23 Info: applyEnvsFromPackageJson OPENCV_LIB_DIR: C:\Users\XXX\vcpkg\vcpkg\installed\x64-windows\lib
2024-08-15 12:27:23 Info: applyEnvsFromPackageJson OPENCV_BIN_DIR: C:\Users\XXX\vcpkg\vcpkg\installed\x64-windows\bin
C:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv4nodejs@7.1.0_typescript@5.5.4\node_modules\@u4\opencv4nodejs\cjs\lib\cvloader.js:105
                throw Error(msg);
                ^

Error: require("C:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv4nodejs@7.1.0_typescript@5.5.4\node_modules\@u4\opencv4nodejs\build\Release\opencv4nodejs");
          Failed with: error: 127\\?\C:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv4nodejs@7.1.0_typescript@5.5.4\node_modules\@u4\opencv4nodejs\build\Release\opencv4nodejs.node

    at getOpenCV (CC:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv4nodejs@7.1.0_typescript@5.5.4\node_modules\@u4\opencv4nodejs\cjs\lib\cvloader.js:105:23)
    at loadOpenCV (C:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv4nodejs@7.1.0_typescript@5.5.4\node_modules\@u4\opencv4nodejs\cjs\lib\opencv4nodejs.js:36:48)
    at Object.<anonymous> (C:\Users\XXX\backend\node_modules\.pnpm\@u4+opencv4nodejs@7.1.0_typescript@5.5.4\node_modules\@u4\opencv4nodejs\cjs\lib\opencv4nodejs.js:58:14)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\Users\XXX\backend\teste.js:1:12)

Node.js v20.10.0
PS C:\Users\XXX\backend>

I tried deleting node_modules and reinstalling everything a few times, but still haven't been able to make it work.

Would deeply appreciate any help!

UrielCh commented 4 weeks ago

I tryed with choco but not with vcpkg

I should add a github action to test that package manager, can you try with chocolatey intead of vcpkg ?

UrielCh commented 4 weeks ago

test in progress: https://github.com/UrielCh/npm-opencv-build/actions/runs/10416302201/job/28848279864

UrielCh commented 3 weeks ago

fixed in @u4/opencv-build@1.1.1

maybeing commented 3 weeks ago

Switching to Chocolatey did work after just a few more adjusts, thank you!!

UrielCh commented 3 weeks ago

fixed in V7.1.1