node-native-win-utils 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -27
- package/binding.gyp +18 -5
- package/dist/index.d.ts +146 -4
- package/dist/index.js +107 -3
- package/include/opencv2/core/affine.hpp +678 -0
- package/include/opencv2/core/async.hpp +105 -0
- package/include/opencv2/core/base.hpp +664 -0
- package/include/opencv2/core/bindings_utils.hpp +325 -0
- package/include/opencv2/core/bufferpool.hpp +40 -0
- package/include/opencv2/core/check.hpp +170 -0
- package/include/opencv2/core/core.hpp +48 -0
- package/include/opencv2/core/core_c.h +3128 -0
- package/include/opencv2/core/cuda/block.hpp +211 -0
- package/include/opencv2/core/cuda/border_interpolate.hpp +722 -0
- package/include/opencv2/core/cuda/color.hpp +309 -0
- package/include/opencv2/core/cuda/common.hpp +131 -0
- package/include/opencv2/core/cuda/datamov_utils.hpp +113 -0
- package/include/opencv2/core/cuda/detail/color_detail.hpp +2018 -0
- package/include/opencv2/core/cuda/detail/reduce.hpp +365 -0
- package/include/opencv2/core/cuda/detail/reduce_key_val.hpp +502 -0
- package/include/opencv2/core/cuda/detail/transform_detail.hpp +392 -0
- package/include/opencv2/core/cuda/detail/type_traits_detail.hpp +191 -0
- package/include/opencv2/core/cuda/detail/vec_distance_detail.hpp +121 -0
- package/include/opencv2/core/cuda/dynamic_smem.hpp +88 -0
- package/include/opencv2/core/cuda/emulation.hpp +269 -0
- package/include/opencv2/core/cuda/filters.hpp +293 -0
- package/include/opencv2/core/cuda/funcattrib.hpp +79 -0
- package/include/opencv2/core/cuda/functional.hpp +805 -0
- package/include/opencv2/core/cuda/limits.hpp +128 -0
- package/include/opencv2/core/cuda/reduce.hpp +209 -0
- package/include/opencv2/core/cuda/saturate_cast.hpp +292 -0
- package/include/opencv2/core/cuda/scan.hpp +258 -0
- package/include/opencv2/core/cuda/simd_functions.hpp +869 -0
- package/include/opencv2/core/cuda/transform.hpp +75 -0
- package/include/opencv2/core/cuda/type_traits.hpp +90 -0
- package/include/opencv2/core/cuda/utility.hpp +230 -0
- package/include/opencv2/core/cuda/vec_distance.hpp +232 -0
- package/include/opencv2/core/cuda/vec_math.hpp +923 -0
- package/include/opencv2/core/cuda/vec_traits.hpp +288 -0
- package/include/opencv2/core/cuda/warp.hpp +139 -0
- package/include/opencv2/core/cuda/warp_reduce.hpp +76 -0
- package/include/opencv2/core/cuda/warp_shuffle.hpp +162 -0
- package/include/opencv2/core/cuda.hpp +1279 -0
- package/include/opencv2/core/cuda.inl.hpp +763 -0
- package/include/opencv2/core/cuda_stream_accessor.hpp +86 -0
- package/include/opencv2/core/cuda_types.hpp +144 -0
- package/include/opencv2/core/cv_cpu_dispatch.h +381 -0
- package/include/opencv2/core/cv_cpu_helper.h +550 -0
- package/include/opencv2/core/cvdef.h +973 -0
- package/include/opencv2/core/cvstd.hpp +190 -0
- package/include/opencv2/core/cvstd.inl.hpp +197 -0
- package/include/opencv2/core/cvstd_wrapper.hpp +154 -0
- package/include/opencv2/core/detail/async_promise.hpp +71 -0
- package/include/opencv2/core/detail/dispatch_helper.impl.hpp +49 -0
- package/include/opencv2/core/detail/exception_ptr.hpp +27 -0
- package/include/opencv2/core/directx.hpp +184 -0
- package/include/opencv2/core/dualquaternion.hpp +979 -0
- package/include/opencv2/core/dualquaternion.inl.hpp +487 -0
- package/include/opencv2/core/eigen.hpp +402 -0
- package/include/opencv2/core/fast_math.hpp +433 -0
- package/include/opencv2/core/hal/hal.hpp +256 -0
- package/include/opencv2/core/hal/interface.h +190 -0
- package/include/opencv2/core/hal/intrin.hpp +939 -0
- package/include/opencv2/core/hal/intrin_avx.hpp +3177 -0
- package/include/opencv2/core/hal/intrin_avx512.hpp +3090 -0
- package/include/opencv2/core/hal/intrin_cpp.hpp +3321 -0
- package/include/opencv2/core/hal/intrin_forward.hpp +191 -0
- package/include/opencv2/core/hal/intrin_lasx.hpp +3236 -0
- package/include/opencv2/core/hal/intrin_msa.hpp +1887 -0
- package/include/opencv2/core/hal/intrin_neon.hpp +2610 -0
- package/include/opencv2/core/hal/intrin_rvv.hpp +3320 -0
- package/include/opencv2/core/hal/intrin_rvv071.hpp +2545 -0
- package/include/opencv2/core/hal/intrin_rvv_scalable.hpp +2080 -0
- package/include/opencv2/core/hal/intrin_sse.hpp +3467 -0
- package/include/opencv2/core/hal/intrin_sse_em.hpp +180 -0
- package/include/opencv2/core/hal/intrin_vsx.hpp +1608 -0
- package/include/opencv2/core/hal/intrin_wasm.hpp +2782 -0
- package/include/opencv2/core/hal/msa_macros.h +1558 -0
- package/include/opencv2/core/hal/simd_utils.impl.hpp +186 -0
- package/include/opencv2/core/llapi/llapi.h +102 -0
- package/include/opencv2/core/mat.hpp +3775 -0
- package/include/opencv2/core/mat.inl.hpp +3422 -0
- package/include/opencv2/core/matx.hpp +1536 -0
- package/include/opencv2/core/neon_utils.hpp +128 -0
- package/include/opencv2/core/ocl.hpp +917 -0
- package/include/opencv2/core/ocl_genbase.hpp +69 -0
- package/include/opencv2/core/opencl/ocl_defs.hpp +82 -0
- package/include/opencv2/core/opencl/opencl_info.hpp +212 -0
- package/include/opencv2/core/opencl/opencl_svm.hpp +81 -0
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clblas.hpp +602 -0
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clfft.hpp +146 -0
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp +371 -0
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp +272 -0
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp +62 -0
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp +42 -0
- package/include/opencv2/core/opencl/runtime/opencl_clblas.hpp +53 -0
- package/include/opencv2/core/opencl/runtime/opencl_clfft.hpp +53 -0
- package/include/opencv2/core/opencl/runtime/opencl_core.hpp +84 -0
- package/include/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp +47 -0
- package/include/opencv2/core/opencl/runtime/opencl_gl.hpp +53 -0
- package/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp +47 -0
- package/include/opencv2/core/opencl/runtime/opencl_svm_20.hpp +48 -0
- package/include/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp +42 -0
- package/include/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp +166 -0
- package/include/opencv2/core/opengl.hpp +733 -0
- package/include/opencv2/core/openvx/ovx_defs.hpp +48 -0
- package/include/opencv2/core/operations.hpp +610 -0
- package/include/opencv2/core/optim.hpp +302 -0
- package/include/opencv2/core/ovx.hpp +28 -0
- package/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp +72 -0
- package/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp +153 -0
- package/include/opencv2/core/parallel/parallel_backend.hpp +90 -0
- package/include/opencv2/core/persistence.hpp +1350 -0
- package/include/opencv2/core/private/cv_cpu_include_simd_declarations.hpp +30 -0
- package/include/opencv2/core/private.cuda.hpp +169 -0
- package/include/opencv2/core/private.hpp +896 -0
- package/include/opencv2/core/quaternion.hpp +1696 -0
- package/include/opencv2/core/quaternion.inl.hpp +1063 -0
- package/include/opencv2/core/saturate.hpp +180 -0
- package/include/opencv2/core/simd_intrinsics.hpp +87 -0
- package/include/opencv2/core/softfloat.hpp +514 -0
- package/include/opencv2/core/sse_utils.hpp +652 -0
- package/include/opencv2/core/traits.hpp +417 -0
- package/include/opencv2/core/types.hpp +2457 -0
- package/include/opencv2/core/types_c.h +2126 -0
- package/include/opencv2/core/utility.hpp +1229 -0
- package/include/opencv2/core/utils/allocator_stats.hpp +29 -0
- package/include/opencv2/core/utils/allocator_stats.impl.hpp +158 -0
- package/include/opencv2/core/utils/buffer_area.private.hpp +136 -0
- package/include/opencv2/core/utils/configuration.private.hpp +22 -0
- package/include/opencv2/core/utils/filesystem.hpp +82 -0
- package/include/opencv2/core/utils/filesystem.private.hpp +66 -0
- package/include/opencv2/core/utils/fp_control.private.hpp +29 -0
- package/include/opencv2/core/utils/fp_control_utils.hpp +69 -0
- package/include/opencv2/core/utils/instrumentation.hpp +125 -0
- package/include/opencv2/core/utils/lock.private.hpp +119 -0
- package/include/opencv2/core/utils/logger.defines.hpp +42 -0
- package/include/opencv2/core/utils/logger.hpp +218 -0
- package/include/opencv2/core/utils/logtag.hpp +28 -0
- package/include/opencv2/core/utils/plugin_loader.private.hpp +165 -0
- package/include/opencv2/core/utils/tls.hpp +235 -0
- package/include/opencv2/core/utils/trace.hpp +252 -0
- package/include/opencv2/core/utils/trace.private.hpp +421 -0
- package/include/opencv2/core/va_intel.hpp +75 -0
- package/include/opencv2/core/version.hpp +26 -0
- package/include/opencv2/core/vsx_utils.hpp +1047 -0
- package/include/opencv2/core.hpp +3365 -0
- package/include/opencv2/imgcodecs/imgcodecs.hpp +48 -0
- package/include/opencv2/imgcodecs/imgcodecs_c.h +1 -0
- package/include/opencv2/imgcodecs/ios.h +59 -0
- package/include/opencv2/imgcodecs/legacy/constants_c.h +54 -0
- package/include/opencv2/imgcodecs/macosx.h +20 -0
- package/include/opencv2/imgcodecs.hpp +407 -0
- package/include/opencv2/imgproc/bindings.hpp +34 -0
- package/include/opencv2/imgproc/detail/gcgraph.hpp +395 -0
- package/include/opencv2/imgproc/hal/hal.hpp +246 -0
- package/include/opencv2/imgproc/hal/interface.h +46 -0
- package/include/opencv2/imgproc/imgproc.hpp +48 -0
- package/include/opencv2/imgproc/imgproc_c.h +1177 -0
- package/include/opencv2/imgproc/segmentation.hpp +141 -0
- package/include/opencv2/imgproc/types_c.h +659 -0
- package/include/opencv2/imgproc.hpp +5035 -0
- package/include/opencv2/opencv_modules.hpp +17 -0
- package/libs/libjpeg-turbo.lib +0 -0
- package/libs/libpng.lib +0 -0
- package/libs/opencv_core470.lib +0 -0
- package/libs/opencv_imgcodecs470.lib +0 -0
- package/libs/opencv_imgproc470.lib +0 -0
- package/libs/zlib.lib +0 -0
- package/package.json +8 -2
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/cpp/capturewindow.cpp +36 -46
- package/src/cpp/main.cpp +10 -2
- package/src/cpp/opencv.cpp +425 -0
package/README.md
CHANGED
|
@@ -4,19 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
I did it for myself because I didn't feel like dealing with libraries like 'node-ffi' to implement this functionality. Maybe someone will find it useful. It's WINDOWS OS ONLY
|
|
6
6
|
|
|
7
|
-
This package is a native addon for Node.js that allows you to perform various utility operations on Windows systems. It includes key event listeners, window data retrieval, window screenshot capture functionality, mouse movement, mouse click, mouse drag, and typing functionality
|
|
7
|
+
This package is a native addon for Node.js that allows you to perform various utility operations on Windows systems. It includes key event listeners, window data retrieval, window screenshot capture functionality, mouse movement, mouse click, mouse drag, and typing functionality, also I included precompiled libs of OpenCV(core, imgcodecs, imgproc)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
# Installation
|
|
10
10
|
|
|
11
11
|
You can install the package using npm:
|
|
12
12
|
|
|
13
13
|
```shell
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
npm install node-native-win-utils
|
|
16
|
+
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
# Usage
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
## Importing the Package
|
|
20
22
|
|
|
21
23
|
To use the package, import the necessary functions, types, and classes:
|
|
22
24
|
|
|
@@ -26,15 +28,16 @@ import {
|
|
|
26
28
|
keyUpHandler,
|
|
27
29
|
getWindowData,
|
|
28
30
|
captureWindow,
|
|
31
|
+
captureWindowN,
|
|
29
32
|
mouseMove,
|
|
30
33
|
mouseClick,
|
|
31
34
|
mouseDrag,
|
|
32
35
|
typeString,
|
|
33
|
-
|
|
36
|
+
OpenCV,
|
|
34
37
|
} from "node-native-win-utils";
|
|
35
38
|
```
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
## Key Event Listeners
|
|
38
41
|
|
|
39
42
|
The package provides `keyDownHandler` and `keyUpHandler` functions, which allow you to register callbacks for key down and key up events, respectively. The callbacks receive the `keyCode` as a parameter:
|
|
40
43
|
|
|
@@ -52,7 +55,7 @@ keyUpHandler((keyCode) => {
|
|
|
52
55
|
// Key up: 8
|
|
53
56
|
```
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
## Window Data
|
|
56
59
|
|
|
57
60
|
The `getWindowData` function retrieves information about a specific window identified by its name. It returns an object with properties `width`, `height`, `x`, and `y`, representing the window dimensions and position:
|
|
58
61
|
|
|
@@ -64,7 +67,7 @@ console.log("Window data:", windowData);
|
|
|
64
67
|
// Window data: { width: 800, height: 600, x: 50, y: 50 }
|
|
65
68
|
```
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
## Window Capture
|
|
68
71
|
|
|
69
72
|
The `captureWindow` function allows you to capture a screenshot of a specific window identified by its name. Provide the window name and the output path as parameters:
|
|
70
73
|
|
|
@@ -74,7 +77,7 @@ captureWindow("Window Name", "output.png");
|
|
|
74
77
|
// Output: output.png with a screenshot of the window
|
|
75
78
|
```
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
## Mouse Movement
|
|
78
81
|
|
|
79
82
|
The `mouseMove` function allows you to move the mouse to a specific position on the screen. Provide the `posX` and `posY` coordinates as parameters:
|
|
80
83
|
|
|
@@ -82,25 +85,27 @@ The `mouseMove` function allows you to move the mouse to a specific position on
|
|
|
82
85
|
mouseMove(100, 200);
|
|
83
86
|
```
|
|
84
87
|
|
|
85
|
-
|
|
88
|
+
## Mouse Click
|
|
86
89
|
|
|
87
90
|
The `mouseClick` function allows you to perform a mouse click event. Optionally, you can specify the mouse button as a parameter (`"left"`, `"middle"`, or `"right"`). If no button is specified, a left mouse click is performed by default:
|
|
88
91
|
|
|
89
92
|
```javascript
|
|
90
93
|
mouseClick(); // Left mouse click
|
|
94
|
+
|
|
91
95
|
mouseClick("right"); // Right mouse click
|
|
92
96
|
```
|
|
93
97
|
|
|
94
|
-
|
|
98
|
+
## Mouse Drag
|
|
95
99
|
|
|
96
100
|
The `mouseDrag` function allows you to simulate dragging the mouse from one position to another. Provide the starting and ending coordinates (`startX`, `startY`, `endX`, `endY`) as parameters. Optionally, you can specify the speed at which the mouse should be dragged:
|
|
97
101
|
|
|
98
102
|
```javascript
|
|
99
103
|
mouseDrag(100, 200, 300, 400);
|
|
104
|
+
|
|
100
105
|
mouseDrag(100, 200, 300, 400, 100); // Drag with speed 100
|
|
101
106
|
```
|
|
102
107
|
|
|
103
|
-
|
|
108
|
+
## Typing
|
|
104
109
|
|
|
105
110
|
The `typeString` function allows you to simulate typing a string of characters. Provide the string to type as the `stringToType` parameter. Optionally, you can specify
|
|
106
111
|
|
|
@@ -108,10 +113,11 @@ a delay between each character (in milliseconds) using the `delay` parameter:
|
|
|
108
113
|
|
|
109
114
|
```javascript
|
|
110
115
|
typeString("Hello, world!");
|
|
116
|
+
|
|
111
117
|
typeString("Hello, world!", 100); // Type with a delay of 100ms between characters
|
|
112
118
|
```
|
|
113
119
|
|
|
114
|
-
|
|
120
|
+
## Key Listener Class
|
|
115
121
|
|
|
116
122
|
The `KeyListener` class extends the EventEmitter class and simplifies working with the `keyDownHandler` and `keyUpHandler` functions. You can register event listeners for the "keyDown" and "keyUp" events using the `on` method:
|
|
117
123
|
|
|
@@ -131,25 +137,131 @@ listener.on("keyUp", (data) => {
|
|
|
131
137
|
// Key up: 8 Backspace
|
|
132
138
|
```
|
|
133
139
|
|
|
140
|
+
## OpenCV
|
|
141
|
+
|
|
142
|
+
The `OpenCV` class extends the capabilities of the native addon package by providing various image processing functionalities. It allows users to perform operations such as matching templates, blurring images, converting color formats, drawing rectangles, getting image regions, and writing images to files.
|
|
143
|
+
|
|
144
|
+
#### Constructor
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const image = new OpenCV(image: string | ImageData)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Creates a new instance of the `OpenCV` class with the specified image data. The `image` parameter can be either a file path (string) or an existing `ImageData` object.
|
|
151
|
+
|
|
152
|
+
#### Properties
|
|
153
|
+
|
|
154
|
+
##### `imageData: ImageData`
|
|
155
|
+
|
|
156
|
+
Holds the underlying image data that will be used for image processing operations.
|
|
157
|
+
|
|
158
|
+
##### `width: number`
|
|
159
|
+
|
|
160
|
+
Read-only property that returns the width of the image in pixels.
|
|
161
|
+
|
|
162
|
+
##### `height: number`
|
|
163
|
+
|
|
164
|
+
Read-only property that returns the height of the image in pixels.
|
|
165
|
+
|
|
166
|
+
#### Methods
|
|
167
|
+
|
|
168
|
+
##### `matchTemplate(template: ImageData, method?: number | null, mask?: ImageData): OpenCV`
|
|
169
|
+
|
|
170
|
+
Matches a template image with the current image and returns a new `OpenCV` instance containing the result.
|
|
171
|
+
|
|
172
|
+
- `template: ImageData`: The template image data to be matched.
|
|
173
|
+
- `method?: number | null`: (Optional) The matching method to be used. If not provided, the default method will be used.(currently no implemented)
|
|
174
|
+
- `mask?: ImageData`: (Optional) An optional mask image data to be used during the matching process.
|
|
175
|
+
|
|
176
|
+
##### `blur(sizeX: number, sizeY: number): OpenCV`
|
|
177
|
+
|
|
178
|
+
Applies a blur filter to the current image and returns a new `OpenCV` instance containing the blurred result.
|
|
179
|
+
|
|
180
|
+
- `sizeX: number`: The size of the blur kernel in the X direction.
|
|
181
|
+
- `sizeY: number`: The size of the blur kernel in the Y direction.
|
|
182
|
+
|
|
183
|
+
##### `bgrToGray(): OpenCV`
|
|
184
|
+
|
|
185
|
+
Converts the current image from the BGR color format to grayscale and returns a new `OpenCV` instance containing the grayscale result.
|
|
186
|
+
|
|
187
|
+
##### `drawRectangle(start: Point, end: Point, rgb: Color, thickness: number): OpenCV`
|
|
188
|
+
|
|
189
|
+
Draws a rectangle on the current image and returns a new `OpenCV` instance containing the modified result.
|
|
190
|
+
|
|
191
|
+
- `start: Point`: The starting point (top-left) of the rectangle.
|
|
192
|
+
- `end: Point`: The ending point (bottom-right) of the rectangle.
|
|
193
|
+
- `rgb: Color`: The color of the rectangle in the RGB format (e.g., `{ r: 255, g: 0, b: 0 }` for red).
|
|
194
|
+
- `thickness: number`: The thickness of the rectangle's border.
|
|
195
|
+
|
|
196
|
+
##### `getRegion(region: ROI): OpenCV`
|
|
197
|
+
|
|
198
|
+
Extracts a region of interest (ROI) from the current image and returns a new `OpenCV` instance containing the extracted region.
|
|
199
|
+
|
|
200
|
+
- `region: ROI`: An object specifying the region of interest with properties `x`, `y`, `width`, `height`.
|
|
201
|
+
|
|
202
|
+
##### `imwrite(path: string): void`
|
|
203
|
+
|
|
204
|
+
Writes the current image to a file specified by the `path`.
|
|
205
|
+
|
|
206
|
+
- `path: string`: The file path where the image will be saved.
|
|
207
|
+
|
|
134
208
|
## Functions
|
|
135
209
|
|
|
136
|
-
| Function | Parameters
|
|
137
|
-
| -------------- |
|
|
138
|
-
| keyDownHandler | `callback: (keyCode: number) => void`
|
|
139
|
-
| keyUpHandler | `callback: (keyCode: number) => void`
|
|
140
|
-
| getWindowData | `windowName: string`
|
|
141
|
-
| captureWindow | `windowName: string, outputPath: string`
|
|
142
|
-
| mouseMove | `posX: number, posY: number`
|
|
143
|
-
| mouseClick | `button?: "left" \| "middle" \| "right"`
|
|
144
|
-
| mouseDrag | `startX: number, startY: number, endX: number, endY: number, speed?: number`
|
|
145
|
-
| typeString | `stringToType: string, delay?: number`
|
|
146
|
-
|
|
|
147
|
-
| KeyListener.on | `event: "keyUp"`,<br>`callback: (data: { keyCode: number; keyName: string }) => void` | `this` (EventListener) |
|
|
210
|
+
| Function | Parameters | Return Type |
|
|
211
|
+
| -------------- | ---------------------------------------------------------------------------- | ------------ |
|
|
212
|
+
| keyDownHandler | `callback: (keyCode: number) => void` | `void` |
|
|
213
|
+
| keyUpHandler | `callback: (keyCode: number) => void` | `void` |
|
|
214
|
+
| getWindowData | `windowName: string` | `WindowData` |
|
|
215
|
+
| captureWindow | `windowName: string, outputPath: string` | `void` |
|
|
216
|
+
| mouseMove | `posX: number, posY: number` | `boolean` |
|
|
217
|
+
| mouseClick | `button?: "left" \| "middle" \| "right"` | `boolean` |
|
|
218
|
+
| mouseDrag | `startX: number, startY: number, endX: number, endY: number, speed?: number` | `boolean` |
|
|
219
|
+
| typeString | `stringToType: string, delay?: number` | `boolean` |
|
|
220
|
+
| captureWindowN | `windowName: string` | `Buffer` |
|
|
148
221
|
|
|
149
222
|
## Examples
|
|
150
223
|
|
|
151
224
|
Here are some examples of using the package:
|
|
152
225
|
|
|
226
|
+
```javascript
|
|
227
|
+
// Example usage of the OpenCV class
|
|
228
|
+
import { OpenCV } from "node-native-win-utils";
|
|
229
|
+
|
|
230
|
+
const image = new OpenCV("path/to/image.png");
|
|
231
|
+
|
|
232
|
+
const template = new OpenCV("path/to/template.png");
|
|
233
|
+
const matchedImage = image.matchTemplate(template.imageData);
|
|
234
|
+
|
|
235
|
+
const blurredImage = image.blur(5, 5);
|
|
236
|
+
|
|
237
|
+
const grayscaleImage = image.bgrToGray();
|
|
238
|
+
|
|
239
|
+
const regionOfInterest = { x: 100, y: 100, width: 200, height: 150 };
|
|
240
|
+
const regionImage = image.getRegion(regionOfInterest);
|
|
241
|
+
|
|
242
|
+
const redColor = { r: 255, g: 0, b: 0 };
|
|
243
|
+
const thickRectangle = image.drawRectangle(
|
|
244
|
+
{ x: 50, y: 50 },
|
|
245
|
+
{ x: 150, y: 150 },
|
|
246
|
+
redColor,
|
|
247
|
+
3
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
matchedImage.imwrite("output/matched.png");
|
|
251
|
+
blurredImage.imwrite("output/blurred.png");
|
|
252
|
+
grayscaleImage.imwrite("output/grayscale.png");
|
|
253
|
+
regionImage.imwrite("output/region.png");
|
|
254
|
+
thickRectangle.imwrite("output/thick_rectangle.png");
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
```javascript
|
|
258
|
+
// If you want to aply blur and convert to gray then do it that order:
|
|
259
|
+
image.blur(5, 5).bgrToGray();
|
|
260
|
+
// Otherwise you will get an error.
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Please note that the above example demonstrates the usage of different methods available in the `OpenCV` class. Make sure to replace `"path/to/image.png"` and `"path/to/template.png"` with actual image file paths.
|
|
264
|
+
|
|
153
265
|
```javascript
|
|
154
266
|
import {
|
|
155
267
|
keyDownHandler,
|
|
@@ -198,16 +310,19 @@ mouseMove(100, 200);
|
|
|
198
310
|
// Perform mouse click
|
|
199
311
|
|
|
200
312
|
mouseClick(); // Left mouse click
|
|
313
|
+
|
|
201
314
|
mouseClick("right"); // Right mouse click
|
|
202
315
|
|
|
203
316
|
// Simulate mouse drag
|
|
204
317
|
|
|
205
318
|
mouseDrag(100, 200, 300, 400);
|
|
319
|
+
|
|
206
320
|
mouseDrag(100, 200, 300, 400, 100); // Drag with speed 100
|
|
207
321
|
|
|
208
322
|
// Simulate typing
|
|
209
323
|
|
|
210
324
|
typeString("Hello, world!");
|
|
325
|
+
|
|
211
326
|
typeString("Hello, world!", 100); // Type with a delay of 100ms between characters
|
|
212
327
|
|
|
213
328
|
// Use KeyListener class
|
|
@@ -227,7 +342,9 @@ listener.on("keyUp", (data) => {
|
|
|
227
342
|
// Key up: 8 Backspace
|
|
228
343
|
```
|
|
229
344
|
|
|
230
|
-
P.S.: As my knowledge of C++ is just brief, most of the C++ code is written
|
|
345
|
+
P.S.: As my knowledge of C++ is just brief, most of the C++ code is written with help of GPT-3.5 and GPT-4
|
|
346
|
+
|
|
347
|
+
[OpenCV License](https://github.com/opencv/opencv/blob/master/LICENSE)
|
|
231
348
|
|
|
232
349
|
[license-src]: https://img.shields.io/github/license/nuxt-modules/icon.svg?style=for-the-badge&colorA=18181B&colorB=28CF8D
|
|
233
350
|
[license-href]: https://github.com/RynerNO/node-native-win-utils/blob/main/LICENSE
|
package/binding.gyp
CHANGED
|
@@ -6,13 +6,25 @@
|
|
|
6
6
|
"openssl_flips": "",
|
|
7
7
|
"include_dirs": [
|
|
8
8
|
"<!@(node -p \"require('node-addon-api').include\")",
|
|
9
|
-
"src/cpp"
|
|
9
|
+
"src/cpp",
|
|
10
|
+
"libs",
|
|
11
|
+
"include",
|
|
12
|
+
"dll"
|
|
10
13
|
],
|
|
11
14
|
"dependencies": [
|
|
12
15
|
"<!(node -p \"require('node-addon-api').gyp\")"
|
|
13
16
|
],
|
|
14
|
-
"libraries": [
|
|
15
|
-
|
|
17
|
+
"libraries": [
|
|
18
|
+
"dwmapi.lib",
|
|
19
|
+
"windowsapp.lib",
|
|
20
|
+
"<!(node -p \"require('path').resolve('libs/libjpeg-turbo.lib')\")",
|
|
21
|
+
"<!(node -p \"require('path').resolve('libs/libpng.lib')\")",
|
|
22
|
+
"<!(node -p \"require('path').resolve('libs/zlib.lib')\")",
|
|
23
|
+
"<!(node -p \"require('path').resolve('libs/opencv_core470.lib')\")",
|
|
24
|
+
"<!(node -p \"require('path').resolve('libs/opencv_imgcodecs470.lib')\")",
|
|
25
|
+
"<!(node -p \"require('path').resolve('libs/opencv_imgproc470.lib')\")",
|
|
26
|
+
|
|
27
|
+
],
|
|
16
28
|
"conditions": [
|
|
17
29
|
["OS=='win'", {
|
|
18
30
|
"defines": [
|
|
@@ -25,9 +37,10 @@
|
|
|
25
37
|
}
|
|
26
38
|
}]
|
|
27
39
|
],
|
|
40
|
+
"defines": ["NAPI_CPP_EXCEPTIONS"],
|
|
28
41
|
"cflags!": ["-fno-exceptions"],
|
|
29
|
-
"cflags_cc!": ["-fno-
|
|
30
|
-
"
|
|
42
|
+
"cflags_cc!": ["-fno-rtti"],
|
|
43
|
+
"cflags": ["/std:c++17"]
|
|
31
44
|
}
|
|
32
45
|
]
|
|
33
46
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,173 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import EventEmitter = require("events");
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Represents the data of a window.
|
|
6
|
+
*/
|
|
7
|
+
export type WindowData = {
|
|
4
8
|
width: number;
|
|
5
9
|
height: number;
|
|
6
10
|
x: number;
|
|
7
11
|
y: number;
|
|
8
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents the data of an image.
|
|
15
|
+
*/
|
|
16
|
+
export type ImageData = {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
data: Uint8Array;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Represents the result of a template matching operation.
|
|
23
|
+
*/
|
|
24
|
+
export type MatchData = {
|
|
25
|
+
minValue: number;
|
|
26
|
+
maxValue: number;
|
|
27
|
+
minLocation: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
};
|
|
31
|
+
maxLocation: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
9
36
|
export type GetWindowData = (windowName: string) => WindowData;
|
|
10
|
-
export type CaptureWindow = (windowName: string
|
|
37
|
+
export type CaptureWindow = (windowName: string) => Buffer;
|
|
38
|
+
/**
|
|
39
|
+
* The handler to listen to key-down events.
|
|
40
|
+
* @param callback - The callback function to handle key-down events.
|
|
41
|
+
*/
|
|
11
42
|
export type KeyDownHandler = (callback: (keyCode: number) => void) => void;
|
|
43
|
+
/**
|
|
44
|
+
* The handler to listen to key-up events.
|
|
45
|
+
* @param callback - The callback function to handle key-up events.
|
|
46
|
+
*/
|
|
12
47
|
export type KeyUpHandler = (callback: (keyCode: number) => void) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Function type for moving the mouse.
|
|
50
|
+
*/
|
|
13
51
|
export type MouseMove = (posX: number, posY: number) => boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Function type for simulating a mouse click.
|
|
54
|
+
*/
|
|
14
55
|
export type MouseClick = (button?: "left" | "middle" | "right") => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Function type for simulating typing.
|
|
58
|
+
*/
|
|
15
59
|
export type TypeString = (stringToType: string, delay?: number) => boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Function type for simulating a mouse drag operation.
|
|
62
|
+
*/
|
|
16
63
|
export type MouseDrag = (starX: number, startY: number, endX: Number, endY: number, speed?: number) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Represents a point in a two-dimensional space.
|
|
66
|
+
*/
|
|
67
|
+
export type Point = [x: number, y: number];
|
|
68
|
+
export type Color = [r: number, g: number, b: number];
|
|
69
|
+
/**
|
|
70
|
+
* Represents a region of interest in an image.
|
|
71
|
+
*/
|
|
72
|
+
export type ROI = [x: number, y: number, width: number, height: number];
|
|
73
|
+
export type Imread = (path: string) => ImageData;
|
|
74
|
+
export type Imwrite = (image: ImageData) => Buffer;
|
|
75
|
+
export type MatchTemplate = (image: ImageData, template: ImageData, method?: number | null, mask?: ImageData) => MatchData;
|
|
76
|
+
export type Blur = (image: ImageData, sizeX: number, sizeY: number) => ImageData;
|
|
77
|
+
export type BgrToGray = (image: ImageData) => ImageData;
|
|
78
|
+
export type DrawRectangle = (image: ImageData, start: Point, end: Point, rgb: Color, thickness: number) => ImageData;
|
|
79
|
+
export type GetRegion = (image: ImageData, region: ROI) => ImageData;
|
|
80
|
+
declare const keyDownHandler: KeyDownHandler, keyUpHandler: KeyUpHandler, getWindowData: GetWindowData, captureWindowN: CaptureWindow, mouseMove: MouseMove, mouseClick: MouseClick, mouseDrag: MouseDrag, typeString: TypeString;
|
|
81
|
+
/**
|
|
82
|
+
* Captures a window and saves it to a file.
|
|
83
|
+
* @param windowName - The name of the window to capture.
|
|
84
|
+
* @param path - The file path to save the captured image.
|
|
85
|
+
* @returns True if the capture and save operation is successful, otherwise false.
|
|
86
|
+
*/
|
|
87
|
+
declare function captureWindow(windowName: string, path: string): boolean;
|
|
17
88
|
export interface KeyListener extends EventEmitter {
|
|
89
|
+
/**
|
|
90
|
+
* Event: Fires when a key is pressed down.
|
|
91
|
+
* @param event - The event name ('keyDown').
|
|
92
|
+
* @param callback - The callback function to handle the event.
|
|
93
|
+
*/
|
|
18
94
|
on(event: "keyDown", callback: (data: {
|
|
19
95
|
keyCode: number;
|
|
20
96
|
keyName: string;
|
|
21
97
|
}) => void): this;
|
|
98
|
+
/**
|
|
99
|
+
* Event: Fires when a key is released.
|
|
100
|
+
* @param event - The event name ('keyUp').
|
|
101
|
+
* @param callback - The callback function to handle the event.
|
|
102
|
+
*/
|
|
22
103
|
on(event: "keyUp", callback: (data: {
|
|
23
104
|
keyCode: number;
|
|
24
105
|
keyName: string;
|
|
25
106
|
}) => void): this;
|
|
26
107
|
}
|
|
27
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Represents a class to listen to keyboard events.
|
|
110
|
+
* @extends EventEmitter
|
|
111
|
+
*/
|
|
28
112
|
export declare class KeyListener extends EventEmitter {
|
|
29
113
|
constructor();
|
|
30
114
|
}
|
|
31
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Represents the OpenCV class that provides image processing functionality.
|
|
117
|
+
*/
|
|
118
|
+
export declare class OpenCV {
|
|
119
|
+
imageData: ImageData;
|
|
120
|
+
/**
|
|
121
|
+
* Represents the OpenCV class that provides image processing functionality.
|
|
122
|
+
*/
|
|
123
|
+
constructor(image: string | ImageData);
|
|
124
|
+
/**
|
|
125
|
+
* The width of the image.
|
|
126
|
+
*/
|
|
127
|
+
get width(): number;
|
|
128
|
+
/**
|
|
129
|
+
* The height of the image.
|
|
130
|
+
*/
|
|
131
|
+
get height(): number;
|
|
132
|
+
/**
|
|
133
|
+
* Matches a template image within the current image.
|
|
134
|
+
* @param template - The template image data to search for.
|
|
135
|
+
* @param method - The template matching method (optional).
|
|
136
|
+
* @param mask - The optional mask image data to apply the operation (optional).
|
|
137
|
+
* @returns The result of the template matching operation.
|
|
138
|
+
*/
|
|
139
|
+
matchTemplate(template: ImageData, method?: number | null, mask?: ImageData): MatchData;
|
|
140
|
+
/**
|
|
141
|
+
* Applies a blur filter to the image.
|
|
142
|
+
* @param sizeX - The horizontal size of the blur filter.
|
|
143
|
+
* @param sizeY - The vertical size of the blur filter.
|
|
144
|
+
* @returns A new OpenCV instance with the blurred image data.
|
|
145
|
+
*/
|
|
146
|
+
blur(sizeX: number, sizeY: number): OpenCV;
|
|
147
|
+
/**
|
|
148
|
+
* Converts the image from BGR to grayscale.
|
|
149
|
+
* @returns A new OpenCV instance with the grayscale image data.
|
|
150
|
+
*/
|
|
151
|
+
bgrToGray(): OpenCV;
|
|
152
|
+
/**
|
|
153
|
+
* Draws a rectangle on the image.
|
|
154
|
+
* @param start - The starting point of the rectangle.
|
|
155
|
+
* @param end - The ending point of the rectangle.
|
|
156
|
+
* @param rgb - The color (RGB) of the rectangle.
|
|
157
|
+
* @param thickness - The thickness of the rectangle's border.
|
|
158
|
+
* @returns A new OpenCV instance with the image containing the drawn rectangle.
|
|
159
|
+
*/
|
|
160
|
+
drawRectangle(start: Point, end: Point, rgb: Color, thickness: number): OpenCV;
|
|
161
|
+
/**
|
|
162
|
+
* Extracts a region of interest (ROI) from the image.
|
|
163
|
+
* @param region - The region of interest defined as [x, y, width, height].
|
|
164
|
+
* @returns A new OpenCV instance with the extracted region of interest.
|
|
165
|
+
*/
|
|
166
|
+
getRegion(region: ROI): OpenCV;
|
|
167
|
+
/**
|
|
168
|
+
* Writes the image data to a file.
|
|
169
|
+
* @param path - The file path to save the image.
|
|
170
|
+
*/
|
|
171
|
+
imwrite(path: string): void;
|
|
172
|
+
}
|
|
173
|
+
export { keyDownHandler, keyUpHandler, getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, };
|
package/dist/index.js
CHANGED
|
@@ -3,20 +3,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.typeString = exports.mouseDrag = exports.mouseClick = exports.mouseMove = exports.captureWindow = exports.getWindowData = exports.keyUpHandler = exports.keyDownHandler = exports.KeyListener = void 0;
|
|
6
|
+
exports.typeString = exports.mouseDrag = exports.mouseClick = exports.mouseMove = exports.captureWindowN = exports.captureWindow = exports.getWindowData = exports.keyUpHandler = exports.keyDownHandler = exports.OpenCV = exports.KeyListener = void 0;
|
|
7
7
|
const EventEmitter = require("events");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
10
|
const bindings = require("node-gyp-build")(path_1.default.resolve(__dirname, ".."));
|
|
10
11
|
const keyCodes_1 = __importDefault(require("./keyCodes"));
|
|
11
|
-
const { keyDownHandler, keyUpHandler, getWindowData,
|
|
12
|
+
const { keyDownHandler, keyUpHandler, getWindowData, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, } = bindings;
|
|
12
13
|
exports.keyDownHandler = keyDownHandler;
|
|
13
14
|
exports.keyUpHandler = keyUpHandler;
|
|
14
15
|
exports.getWindowData = getWindowData;
|
|
15
|
-
exports.
|
|
16
|
+
exports.captureWindowN = captureWindowN;
|
|
16
17
|
exports.mouseMove = mouseMove;
|
|
17
18
|
exports.mouseClick = mouseClick;
|
|
18
19
|
exports.mouseDrag = mouseDrag;
|
|
19
20
|
exports.typeString = typeString;
|
|
21
|
+
/**
|
|
22
|
+
* Captures a window and saves it to a file.
|
|
23
|
+
* @param windowName - The name of the window to capture.
|
|
24
|
+
* @param path - The file path to save the captured image.
|
|
25
|
+
* @returns True if the capture and save operation is successful, otherwise false.
|
|
26
|
+
*/
|
|
27
|
+
function captureWindow(windowName, path) {
|
|
28
|
+
const buffer = captureWindowN(windowName);
|
|
29
|
+
if (!buffer)
|
|
30
|
+
return false;
|
|
31
|
+
fs_1.default.writeFileSync(path, buffer);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
exports.captureWindow = captureWindow;
|
|
35
|
+
/**
|
|
36
|
+
* Represents a class to listen to keyboard events.
|
|
37
|
+
* @extends EventEmitter
|
|
38
|
+
*/
|
|
20
39
|
class KeyListener extends EventEmitter {
|
|
21
40
|
constructor() {
|
|
22
41
|
super();
|
|
@@ -37,3 +56,88 @@ class KeyListener extends EventEmitter {
|
|
|
37
56
|
}
|
|
38
57
|
}
|
|
39
58
|
exports.KeyListener = KeyListener;
|
|
59
|
+
/**
|
|
60
|
+
* Represents the OpenCV class that provides image processing functionality.
|
|
61
|
+
*/
|
|
62
|
+
class OpenCV {
|
|
63
|
+
imageData;
|
|
64
|
+
/**
|
|
65
|
+
* Represents the OpenCV class that provides image processing functionality.
|
|
66
|
+
*/
|
|
67
|
+
constructor(image) {
|
|
68
|
+
if (typeof image === "string") {
|
|
69
|
+
this.imageData = imread(image);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.imageData = image;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The width of the image.
|
|
77
|
+
*/
|
|
78
|
+
get width() {
|
|
79
|
+
return this.imageData.width;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The height of the image.
|
|
83
|
+
*/
|
|
84
|
+
get height() {
|
|
85
|
+
return this.imageData.height;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Matches a template image within the current image.
|
|
89
|
+
* @param template - The template image data to search for.
|
|
90
|
+
* @param method - The template matching method (optional).
|
|
91
|
+
* @param mask - The optional mask image data to apply the operation (optional).
|
|
92
|
+
* @returns The result of the template matching operation.
|
|
93
|
+
*/
|
|
94
|
+
matchTemplate(template, method, mask) {
|
|
95
|
+
return matchTemplate(this.imageData, template, method, mask);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Applies a blur filter to the image.
|
|
99
|
+
* @param sizeX - The horizontal size of the blur filter.
|
|
100
|
+
* @param sizeY - The vertical size of the blur filter.
|
|
101
|
+
* @returns A new OpenCV instance with the blurred image data.
|
|
102
|
+
*/
|
|
103
|
+
blur(sizeX, sizeY) {
|
|
104
|
+
return new OpenCV(blur(this.imageData, sizeX, sizeY));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Converts the image from BGR to grayscale.
|
|
108
|
+
* @returns A new OpenCV instance with the grayscale image data.
|
|
109
|
+
*/
|
|
110
|
+
bgrToGray() {
|
|
111
|
+
return new OpenCV(bgrToGray(this.imageData));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Draws a rectangle on the image.
|
|
115
|
+
* @param start - The starting point of the rectangle.
|
|
116
|
+
* @param end - The ending point of the rectangle.
|
|
117
|
+
* @param rgb - The color (RGB) of the rectangle.
|
|
118
|
+
* @param thickness - The thickness of the rectangle's border.
|
|
119
|
+
* @returns A new OpenCV instance with the image containing the drawn rectangle.
|
|
120
|
+
*/
|
|
121
|
+
drawRectangle(start, end, rgb, thickness) {
|
|
122
|
+
return new OpenCV(drawRectangle(this.imageData, start, end, rgb, thickness));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Extracts a region of interest (ROI) from the image.
|
|
126
|
+
* @param region - The region of interest defined as [x, y, width, height].
|
|
127
|
+
* @returns A new OpenCV instance with the extracted region of interest.
|
|
128
|
+
*/
|
|
129
|
+
getRegion(region) {
|
|
130
|
+
return new OpenCV(getRegion(this.imageData, region));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Writes the image data to a file.
|
|
134
|
+
* @param path - The file path to save the image.
|
|
135
|
+
*/
|
|
136
|
+
imwrite(path) {
|
|
137
|
+
const buffer = imwrite(this.imageData);
|
|
138
|
+
if (!buffer)
|
|
139
|
+
return;
|
|
140
|
+
fs_1.default.writeFileSync(path, buffer);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.OpenCV = OpenCV;
|