Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

major upgrade #133

Merged
merged 50 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2606c84
reformat project structure
UrielCh Apr 17, 2024
146f16b
migration esm + CJS
UrielCh Apr 17, 2024
0951c28
ESM build pass
UrielCh Apr 17, 2024
df860ec
update deps
UrielCh Apr 17, 2024
668c682
lint
UrielCh Apr 17, 2024
57abfeb
lint code
UrielCh Apr 17, 2024
db17b02
update export files list
UrielCh Apr 17, 2024
b1f6ef9
drom nodenext in tsconfig
UrielCh Apr 18, 2024
e0fb5ca
patch exports
UrielCh Apr 20, 2024
2ce2c6a
use next @u4/opencv-build
UrielCh Apr 26, 2024
f7ad09e
fix export order
UrielCh Apr 26, 2024
420613a
roolback
UrielCh Apr 26, 2024
6dcf526
clean tsconfig
UrielCh Apr 27, 2024
f83b21e
prepare 7.0.0-alpha-5
UrielCh Apr 27, 2024
33c28b9
separeted types generation
UrielCh Apr 28, 2024
495d3df
add rebuild task
UrielCh Apr 28, 2024
dbd220e
rename invalid haarcascades filename
UrielCh Apr 28, 2024
2f9cd5e
remove one any usage
UrielCh Apr 28, 2024
b23fa2e
add extention in import
UrielCh Apr 28, 2024
a843ff6
move ESM / CJS depentend code to an isolated file.
UrielCh Apr 28, 2024
6563893
update meta.ts
UrielCh Apr 28, 2024
e02d34b
drop __dirname usage
UrielCh Apr 28, 2024
f9477c6
regen types
UrielCh Apr 28, 2024
35c5229
prepare alpha-6
UrielCh Apr 28, 2024
bdf3243
ESM PASS
UrielCh Apr 28, 2024
4231f24
update chai 5
UrielCh Apr 28, 2024
4d764ef
updare deps
UrielCh Apr 28, 2024
83959ad
update eslint + lint
UrielCh Apr 28, 2024
5f0e9fa
lint
UrielCh Apr 28, 2024
f75957a
add files to packages
UrielCh Apr 28, 2024
9085598
fix import chai error
UrielCh Apr 29, 2024
38bbe3f
use less __dirname
UrielCh Apr 29, 2024
674d735
add pnpm run rebuild in appveyor
UrielCh Apr 29, 2024
09a957a
update appveyor to build V4.9.0
UrielCh Apr 30, 2024
f155130
patch examples
UrielCh Apr 30, 2024
3531f39
use ESM import style in examples
UrielCh Apr 30, 2024
64322ad
fix Export structure.
UrielCh Apr 30, 2024
766d9b3
fix typings + improve exports
UrielCh Apr 30, 2024
d80fc6e
improve typing
UrielCh Apr 30, 2024
4b4d1ef
switch examples to ESM modules
UrielCh Apr 30, 2024
5e4f70f
@u4/[email protected]
UrielCh Apr 30, 2024
25a952b
fix 2 ESM import
UrielCh Apr 30, 2024
7fc720c
add DNN_BACKEND_WEBNN
UrielCh Apr 30, 2024
3ee00ab
clean exports
UrielCh Apr 30, 2024
03d8315
update appveyor + refactor
UrielCh Apr 30, 2024
2c31eb0
tsconfig is now strict
UrielCh Apr 30, 2024
55bf9d8
fix strict type error
UrielCh Apr 30, 2024
324d47b
prepare Version 7
UrielCh Apr 30, 2024
2e703f6
use @u4/[email protected]
UrielCh Apr 30, 2024
6ac85ed
update Readme
UrielCh Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions .eslintrc

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ cjs/install/
cjs/lib/
esm/install/
esm/lib/
u4-opencv4nodejs-*.tgz
examples/yolo_out_py.avi
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# changelog

## Version 7.0.0
- Updated code to ESM.
- Introduced new exports model.
- Fixed typing errors.
- Added missing types.
- Removed typing duplication in codebase.
- Native code is now generated directly by the default node-gyp rebuild.
- GitHub actions now test all available Windows, macOS, and Linux environments.

## Version 6.6.0
- update gcc flag to enable C++ 17
- fix code to support latest onpenCV version up to 4.9
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Opencv4nodejs can be linked to a prebuild openCV 3 or 4. or can build its own openCV using [@u4/opencv-build](https://www.npmjs.com/package/@u4/opencv-build),
In this case, you have to choose which version you want to link.

> Since version 7, you should be able to use this module directly without any configuration if you have OpenCV installed from your package manager (Chocolatey / Brew / apt).

### To use your OWN openCV build

**3 way to use your own openCV (Without automatic building)**
Expand Down Expand Up @@ -54,7 +56,7 @@ OPENCV_BUILD_ROOT=~/opencv

#### 1) Environment variable
Define environment variable:
- `OPENCV4NODEJS_AUTOBUILD_OPENCV_VERSION`="4.6.0"
- `OPENCV4NODEJS_AUTOBUILD_OPENCV_VERSION`="4.9.0"

#### 2) package.json
Define an opencv4nodejs section in your package.json like:
Expand Down Expand Up @@ -660,7 +662,7 @@ try {
## With TypeScript

``` javascript
import * as cv from '@u4/opencv4nodejs'
import cv from '@u4/opencv4nodejs'
```

Check out the TypeScript [examples](https://github.com/urielch/opencv4nodejs/tree/master/examples).
Expand Down
13 changes: 7 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ shallow_clone: true
# what combinations to test
environment:
OPENCV3_N0: 3.4.16 # 2021-10-11
#OPENCV4_N_0: 4.6.0 # 2022-06-12
OPENCV4_N0: 4.5.5 # 2022-06-12
OPENCV4_N1: 4.5.0 # 2021-12-30
OPENCV4_N2: 4.4.0 # 2020-07-18
OPENCV4_N0: 4.9.0 # 2022-06-12
# OPENCV4_N0: 4.5.5 # 2022-06-12
# OPENCV4_N1: 4.5.0 # 2021-12-30
# OPENCV4_N2: 4.4.0 # 2020-07-18

# OPENCV4_N0: 4.5.3 #
# OPENCV4_N1: 4.5.2 #
Expand Down Expand Up @@ -69,8 +69,8 @@ environment:
install:
- cmd: choco install OpenCV -y --version %OPENCVV%
- if not "%BUILD_TASK%" == "ENVS" SET OPENCV_INCLUDE_DIR=c:\tools\opencv\build\include
- if not "%BUILD_TASK%" == "ENVS" SET OPENCV_LIB_DIR=c:\tools\opencv\build\x64\vc14\lib
- if not "%BUILD_TASK%" == "ENVS" SET OPENCV_BIN_DIR=c:\tools\opencv\build\x64\vc14\bin
- if not "%BUILD_TASK%" == "ENVS" SET OPENCV_LIB_DIR=c:\tools\opencv\build\x64\vc16\lib
- if not "%BUILD_TASK%" == "ENVS" SET OPENCV_BIN_DIR=c:\tools\opencv\build\x64\vc16\bin
- if not "%BUILD_TASK%" == "ENVS" SET PATH=%PATH%;%OPENCV_BIN_DIR%;
- ps: Install-Product node $env:NODEV x64
# - node --version
Expand All @@ -86,6 +86,7 @@ test_script:
- cd c:\projects\opencv4nodejs
- pnpm install --frozen-lockfile
- pnpm run prepack
- pnpm run rebuild
# - npm link
# - build-opencv rebuild
# - cd c:\projects\opencv4nodejs\ci\envs && build-opencv rebuild && pnpm install && pnpm test
Expand Down
2 changes: 1 addition & 1 deletion bin/install.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
const compileLib = require("../install/compileLib.js");
const compileLib = require("../cjs/install/compileLib.js");
const {argv} = process;
compileLib.compileLib(argv);
4 changes: 2 additions & 2 deletions bin/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
import * as compileLib from "../install/compileLib";
import { compileLib } from "../src/install/compileLib";
const {argv} = process;
compileLib.compileLib(argv);
compileLib(argv);
4 changes: 4 additions & 0 deletions cc/dnn/dnn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ NAN_MODULE_INIT(Dnn::Init) {
FF_CONST_TYPE(DNN_TARGET_HDDL, cv::dnn::DNN_TARGET_HDDL)
#endif

#if CV_VERSION_GREATER_EQUAL(4, 8, 0)
FF_CONST_TYPE(DNN_BACKEND_WEBNN, cv::dnn::DNN_BACKEND_WEBNN)
#endif


Net::Init(target);

Expand Down
3 changes: 3 additions & 0 deletions cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
36 changes: 36 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// @ts-check
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: [
"test/**/*.ts",
"**/*.js",
"types/**/*.d.ts",
"src/lib/meta.ts",
],
}
,
{"rules": {
"linebreak-style": 0,
"comma-dangle": ["error", "always-multiline"],
"no-plusplus": "off",
"import/no-unresolved": 0,
"import/extensions": 0,
"import/no-extraneous-dependencies": 0,
"no-async-promise-executor": 0,
"radix": 1,
"no-undef": 0,
"no-case-declarations": 0,
// unit tests only
// "max-len" : 0,
// "no-new" : 0,
// "no-unused-expressions": 0,
// "prefer-spread": 0,
// "@typescript-eslint/ban-ts-comment": 0,
// "@typescript-eslint/no-explicit-any": 0
}},
);
3 changes: 3 additions & 0 deletions esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
9 changes: 5 additions & 4 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
"name": "opencv4nodejs-examples",
"version": "0.0.0",
"description": "example for opencv4nodejs",
"main": "EASTTextDetection.js",
"main": "src/EASTTextDetection.js",
"type": "module",
"scripts": {
"clean": "rimraf src/**/*.js src/**/*.map *.js.map *.js *.log"
"clean": "rimraf src/*.js src/**/*.js src/**/*.map *.js.map *.js *.log"
},
"author": "",
"license": "MIT",
"dependencies": {
"@types/lodash.samplesize": "^4.2.9",
"@u4/opencv4nodejs": "link:..",
"axios": "^1.2.2",
"axios": "^1.6.8",
"lodash.samplesize": "^4.2.0",
"mri": "^1.2.0",
"p-limit": "3.1.0",
"p-limit": "5.0.0",
"picocolors": "^1.0.0",
"progress": "^2.0.3"
},
Expand Down
32 changes: 16 additions & 16 deletions examples/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions examples/src/AgeGender/AgeGender.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs';
import fs from 'node:fs';
import mri from 'mri';
import * as openCV from '@u4/opencv4nodejs';
import { Mat, Net, Point2, Rect, Size, Vec3, VideoCapture } from '@u4/opencv4nodejs';
import { cv, getCachedFile, wait4key } from '../utils';
import path from 'path';
import NetIdentifier from './NetIdentifier';
import { cv, getCachedFile, getExampleDirname, wait4key } from '../utils.js';
import NetIdentifier from './NetIdentifier.js';

// ported from https://github.com/spmallick/learnopencv/blob/master/AgeGender/AgeGender.py

Expand Down Expand Up @@ -48,23 +48,28 @@ if (args.help) {
}

const main = async () => {
const faceProto = path.resolve(__dirname, "opencv_face_detector.pbtxt")
const faceModel = await getCachedFile(path.resolve(__dirname, "opencv_face_detector_uint8.pb"), 'https://github.com/spmallick/learnopencv/raw/master/AgeGender/opencv_face_detector_uint8.pb')
const faceProto = getExampleDirname("AgeGender", "opencv_face_detector.pbtxt")
const faceModel = await getCachedFile(getExampleDirname("AgeGender", "opencv_face_detector_uint8.pb"), 'https://github.com/spmallick/learnopencv/raw/master/AgeGender/opencv_face_detector_uint8.pb')

const ageProto = path.resolve(__dirname, "age_deploy.prototxt")
const ageProto = getExampleDirname("AgeGender", "age_deploy.prototxt")
// 44 MB file
const ageModel = path.resolve(__dirname, "age_net.caffemodel") // https://www.dropbox.com/s/xfb20y596869vbb/age_net.caffemodel?dl=0
const ageModel = getExampleDirname("AgeGender", "age_net.caffemodel") // https://www.dropbox.com/s/xfb20y596869vbb/age_net.caffemodel?dl=0

const genderProto = path.resolve(__dirname, "gender_deploy.prototxt")
const genderProto = getExampleDirname("AgeGender", "gender_deploy.prototxt")
// 44 MB file
const genderModel = path.resolve(__dirname, "gender_net.caffemodel") // https://www.dropbox.com/s/iyv483wz7ztr9gh/gender_net.caffemodel?dl=0
const genderModel = getExampleDirname("AgeGender", "gender_net.caffemodel") // https://www.dropbox.com/s/iyv483wz7ztr9gh/gender_net.caffemodel?dl=0

const MODEL_MEAN_VALUES = new Vec3(78.4263377603, 87.7689143744, 114.895847746)

// Load network
if (!fs.existsSync(ageModel)) {
throw Error(`fail to read ${ageModel}`);
throw Error(`fail to read ${ageModel} please download if from https://www.dropbox.com/s/xfb20y596869vbb/age_net.caffemodel?dl=0`);
}

if (!fs.existsSync(genderModel)) {
throw Error(`fail to read ${genderModel} please download if from https://www.dropbox.com/s/iyv483wz7ztr9gh/gender_net.caffemodel?dl=0`);
}

if (!fs.existsSync(ageProto)) {
throw Error(`fail to read ${ageProto}`);
}
Expand Down
1 change: 0 additions & 1 deletion examples/src/AgeGender/NetIdentifier.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import cv, { Net, Mat } from "@u4/opencv4nodejs";


const getMaxIndex = (scores: number[]): number => {
let max = Number.MIN_VALUE;
let classId = -1;
Expand Down
11 changes: 6 additions & 5 deletions examples/src/EASTTextDetection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import { cv, drawBlueRect, getCachedFile, getResourcePath, wait4key } from './utils';
import path from 'node:path';
import type { Mat, Rect } from '@u4/opencv4nodejs';
import { cv, drawBlueRect, getCachedFile, getResourcePath, wait4key } from './utils.js';

/**
* Text detection simple code example.
Expand Down Expand Up @@ -45,7 +45,7 @@ function decode(scores: Mat, geometry: Mat, confThreshold = MIN_CONFIDENCE) {
startX,
startY,
endX - startX,
endY - startY
endY - startY,
));
confidences.push(score);
}
Expand Down Expand Up @@ -81,7 +81,8 @@ async function detection(modelPath: string, imgAbsPath: string): Promise<void> {
const indices = cv.NMSBoxes(
boxes,
confidences,
MIN_CONFIDENCE, NMS_THRESHOLD
MIN_CONFIDENCE,
NMS_THRESHOLD,
);

indices.forEach((i) => {
Expand All @@ -90,7 +91,7 @@ async function detection(modelPath: string, imgAbsPath: string): Promise<void> {
rect.x * widthRatio,
rect.y * heightRatio,
rect.width * widthRatio,
rect.height * heightRatio
rect.height * heightRatio,
)
drawBlueRect(img, imgRect);
});
Expand Down
Loading
Loading