Skip to content

Commit

Permalink
feat: added ci (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyyyyy authored Jan 1, 2025
1 parent 940a457 commit 3193c41
Show file tree
Hide file tree
Showing 10 changed files with 778 additions and 489 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Linux Build Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 'latest'

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake
sudo apt-get install -y libopencv-dev
- name: Set environment variables
run: |
echo "OPENCV_INCLUDE_DIR=/usr/include/opencv4" >> $GITHUB_ENV
echo "OPENCV_LIB_DIR=/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV
- name: Install dependencies and build
run: npm install

- name: Test
run: npm test --if-present
41 changes: 41 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Windows Build Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 'latest'

- name: Install CMake
uses: lukka/get-cmake@latest

- name: Download and Install OpenCV
run: |
$opencvVersion = "4.10.0"
$downloadUrl = "https://github.com/opencv/opencv/releases/download/$opencvVersion/opencv-$opencvVersion-windows.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile "opencv-windows.exe"
Start-Process -FilePath "opencv-windows.exe" -ArgumentList "-y -o`"D:`"" -Wait
- name: Set Environment Variables
run: |
echo "OPENCV_INCLUDE_DIR=D:\opencv\build\include" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "OPENCV_LIB_DIR=D:\opencv\build\x64\vc16\lib" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "D:\opencv\build\x64\vc16\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
- name: Install dependencies and build
run: npm install

- name: Test
run: npm test --if-present
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
PREFIX ""
SUFFIX ".node"
)

add_definitions(-DNODE_ADDON_API_CPP_EXCEPTIONS)
add_definitions(-DNODE_ADDON_API_CPP_EXCEPTIONS_ALL)
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,29 @@ export OPENCV_LIB_DIR=/opt/homebrew/Cellar/opencv/4.10.0_12/lib

### Linux
```bash
export OPENCV_INCLUDE_DIR=/usr/local/include/opencv4
export OPENCV_LIB_DIR=/usr/local/lib
export OPENCV_INCLUDE_DIR=/usr/include/opencv4
export OPENCV_LIB_DIR=/usr/lib/x86_64-linux-gnu
```

## Building and Running

1. Build native module:
```bash
yarn install
npm install
```

2. Use in JavaScript:
```javascript
const addon = require('node-opencv');
const [image1, image2] = await Promise.all([
cv.imdecodeAsync(full),
cv.imdecodeAsync(image),
cv.imdecodeAsync('demo/full.jpg'),
cv.imdecodeAsync('demo/1.jpg'),
]);
const matched = await image1.matchTemplateAsync(image2, cv.TM_CCOEFF_NORMED);
const minMax = await matched.minMaxLocAsync();
console.log(minMax.maxVal * 100);
console.log(cv.getBuildInformation());

```

## Common Issues
Expand Down
9 changes: 4 additions & 5 deletions demo/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ for (let i = 0; i < 5; i++) {
createWorker();
}

setInterval(() => {
const used = process.memoryUsage();

console.log(`${Math.round(used.rss / 1024 / 1024 * 100) / 100} MB`)
}, 1000);
// setTimeout(() => {
// const used = process.memoryUsage();
// console.log(`${Math.round(used.rss / 1024 / 1024 * 100) / 100} MB`)
// }, 1000);
1 change: 1 addition & 0 deletions demo/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function workerTask() {
image2.release();
image3.release();
image4.release();
process.exit();
} catch (error) {
parentPort.postMessage({ error: error.message });
}
Expand Down
Loading

0 comments on commit 3193c41

Please sign in to comment.