How to compile with OpenCv 4.7.0
Sebastian-Habiger opened this issue · 6 comments
Hi,
I am trying to get the library built with OpenCv 4.7.0. Do you think this should be possible and what are the steps involved to accomplish that?
I downloaded the opencv and opencv_contrib source code and managed to compile it with visual studio 2022.
Also, I am not sure if VS2019 is a requirement.
I tried, and v 4.7.0 alllllllmost working. I did not get time to deeply check that.
my progress on windows 11
- git could not checkout 4.7.0 due to the 260Chars limitation of older windows. To fix that long paths must be opt in.
Solution:git config --global core.longpaths true
I looks like 4.7.0 works at least on windows.
But there is something really strange. I've added bindings for the barcode Module from opencv_contrib package.
It does compile, but linking fails because it could not find the symbols of the barcode library.
I've checked if they are inside the Release path and they are.
So my question is: Do I need to opt in the barcode libraries somewhere in the node build package?
opencv_barcode470.exp
opencv_barcode470.lib
"checking for opencv libraries" does not list barcode
info install checking for opencv libraries
info install lib core: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_core470.lib
info install lib imgproc: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_imgproc470.lib
info install lib imgcodecs: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_imgcodecs470.lib
info install lib videoio: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_videoio470.lib
info install lib highgui: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_highgui470.lib
info install lib video: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_video470.lib
info install lib calib3d: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_calib3d470.lib
info install lib features2d: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_features2d470.lib
info install lib objdetect: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_objdetect470.lib
info install lib dnn: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_dnn470.lib
info install lib ml: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_ml470.lib
info install lib flann: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_flann470.lib
info install lib photo: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_photo470.lib
info install lib gapi: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_gapi470.lib
info install lib face: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_face470.lib
info install lib img_hash: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_img_hash470.lib
info install lib text: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_text470.lib
info install lib tracking: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_tracking470.lib
info install lib videostab: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_videostab470.lib
info install lib xfeatures2d: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_xfeatures2d470.lib
info install lib ximgproc: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_ximgproc470.lib
info install all libraries are installed in C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release => Skip building
info install
info install Found the following libs:
info install core: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_core470.lib
info install imgproc: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_imgproc470.lib
info install imgcodecs: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_imgcodecs470.lib
info install videoio: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_videoio470.lib
info install highgui: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_highgui470.lib
info install video: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_video470.lib
info install calib3d: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_calib3d470.lib
info install features2d: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_features2d470.lib
info install objdetect: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_objdetect470.lib
info install dnn: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_dnn470.lib
info install ml: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_ml470.lib
info install flann: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_flann470.lib
info install photo: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_photo470.lib
info install gapi: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_gapi470.lib
info install face: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_face470.lib
info install img_hash: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_img_hash470.lib
info install text: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_text470.lib
info install tracking: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_tracking470.lib
info install videostab: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_videostab470.lib
info install xfeatures2d: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_xfeatures2d470.lib
info install ximgproc: C:\Projects\Telution\telution-omr\service\lib\opencv4nodejs\node_modules\@u4\opencv-build\dist\opencv-4.7.0-8b1ea\build\lib\Release\opencv_ximgproc470.lib
info defines
When set barcode to true inside misc.js of opencv-build it works just fine.
@UrielCh is there another option without messing with the code of opencv-build?
This is how i do it for nestjs projects, should work for any version my example was 4.7.0-r3. The '# Fix code errors' part might not be needed. If it cries for node-gyp add it to the project or install it global.
###################
# BUILD FOR LOCAL DEVELOPMENT
###################
FROM node:18-alpine As development
# Create app directory
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY --chown=node:node package*.json ./
# Install app dependencies using the `npm ci` command instead of `npm install`
RUN npm ci
# Bundle app source
COPY --chown=node:node . .
# Use the node user from the image (instead of the root user)
USER node
###################
# BUILD FOR PRODUCTION
###################
FROM node:18-alpine As build
WORKDIR /usr/src/app
COPY --chown=node:node package*.json ./
# In order to run `npm run build` we need access to the Nest CLI which is a dev dependency. In the previous development stage we ran `npm ci` which installed all dependencies, so we can copy over the node_modules directory from the development image
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules
COPY --chown=node:node . .
# Install opencv
RUN apk add opencv-dev
RUN apk add --no-cache --virtual .build-deps \
build-base \
cmake \
g++ \
gcc \
git \
linux-headers \
make \
python3
ENV OPENCV4NODEJS_DISABLE_AUTOBUILD=1
ENV OPENCV_INCLUDE_DIR=/usr/include/opencv4
ENV OPENCV_LIB_DIR=/usr/lib
ENV OPENCV_BIN_DIR=/usr/bin
# Fix code errors
# node_modules/@u4/opencv4nodejs/typings/FacemarkAAMParams.d.ts:0:2 add import { Point2 } from './Point2';
RUN sed -i '1s/^/import { Point2 } from "\.\/Point2"; /' node_modules/@u4/opencv4nodejs/typings/FacemarkAAMParams.d.ts
# node_modules/@u4/opencv4nodejs/typings/TrackerBoostingParams.d.ts:1:47 remove implements TrackerBoostingParamsI
RUN sed -i '1s/.*/export class TrackerBoostingParams {/' node_modules/@u4/opencv4nodejs/typings/TrackerBoostingParams.d.ts
# Build opencv
RUN npx build-opencv --no-build rebuild
# Run the build command which creates the production bundle
RUN npm run build
# Set NODE_ENV environment variable
ENV NODE_ENV production
# Running `npm ci` removes the existing node_modules directory and passing in --only=production ensures that only the production dependencies are installed. This ensures that the node_modules directory is as optimized as possible
RUN npm ci --only=production && npm cache clean --force
USER node
CMD [ "node", "dist/main.js" ]
hi, I'm currently working on a new opencv binding, so I'm less available for now.