node-native-win-utils 2.1.1 → 2.1.3
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 +1 -8
- package/dist/index.cjs +21 -2
- package/dist/index.d.cts +45 -0
- package/dist/index.d.mts +45 -0
- package/dist/index.mjs +20 -1
- package/package.json +1 -1
- package/prebuilds/win32-x64/node-native-win-utils.node +0 -0
- package/src/cpp/main.cpp +1 -0
- package/src/cpp/opencv.cpp +48 -2
- package/src/index.mts +52 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
[![License][license-src]][license-href]
|
|
3
|
-

|
|
4
4
|
|
|
5
5
|
#### USDT TRC20 - TYAJ3K3MZraJhWimxxeCKcJ2SYABkVsrzi
|
|
6
6
|
#### USDT TON - UQDokuYZXr4OHvfslDqUoFYcp1_F8tcjQPk_TvqSSDk7SIa7
|
|
@@ -24,13 +24,6 @@ I did it for myself because I didn't feel like dealing with libraries like 'node
|
|
|
24
24
|
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)
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
# VESRION 1.3.3
|
|
29
|
-
|
|
30
|
-
Added a new function to simulate button press and release (`keyPress`), introduced an enumeration `KeyCodesHelper` with the most common key codes, and fixed a bug where the `typeString` function was not working with languages other than English.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
27
|
# Installation
|
|
35
28
|
|
|
36
29
|
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ 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.OpenCV = exports.KeyboardListener = exports.captureScreenAsync = exports.textRecognition = exports.KeyCodeHelper = exports.rawPressKey = exports.typeString = exports.mouseDrag = exports.mouseClick = exports.mouseMove = exports.captureWindowN = exports.getWindowData = void 0;
|
|
6
|
+
exports.OpenCV = exports.KeyboardListener = exports.captureScreenAsync = exports.textRecognition = exports.KeyCodeHelper = exports.rawPressKey = exports.typeString = exports.mouseDrag = exports.mouseClick = exports.mouseMove = exports.captureWindowN = exports.getWindowData = exports.TemplateMatchModes = void 0;
|
|
7
7
|
exports.captureWindow = captureWindow;
|
|
8
8
|
exports.keyPress = keyPress;
|
|
9
9
|
exports.captureScreenToFile = captureScreenToFile;
|
|
@@ -17,7 +17,7 @@ const keyCodes_cjs_1 = require("./keyCodes.cjs");
|
|
|
17
17
|
Object.defineProperty(exports, "KeyCodeHelper", { enumerable: true, get: function () { return keyCodes_cjs_1.KeyCodeHelper; } });
|
|
18
18
|
const dirnameLocal_cjs_1 = require("./dirnameLocal.cjs");
|
|
19
19
|
const bindings = nodeGypBuild(path_1.default.resolve(dirnameLocal_cjs_1.__dirnameLocal, ".."));
|
|
20
|
-
const { setKeyDownCallback, setKeyUpCallback, unsetKeyDownCallback, unsetKeyUpCallback, getWindowData, captureWindowN, captureScreenAsync, mouseMove, mouseClick, mouseDrag, typeString, pressKey, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, textRecognition } = bindings;
|
|
20
|
+
const { setKeyDownCallback, setKeyUpCallback, unsetKeyDownCallback, unsetKeyUpCallback, getWindowData, captureWindowN, captureScreenAsync, mouseMove, mouseClick, mouseDrag, typeString, pressKey, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, textRecognition, equalizeHist } = bindings;
|
|
21
21
|
exports.getWindowData = getWindowData;
|
|
22
22
|
exports.captureWindowN = captureWindowN;
|
|
23
23
|
exports.captureScreenAsync = captureScreenAsync;
|
|
@@ -128,6 +128,18 @@ class KeyboardListener {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
exports.KeyboardListener = KeyboardListener;
|
|
131
|
+
var TemplateMatchModes;
|
|
132
|
+
(function (TemplateMatchModes) {
|
|
133
|
+
TemplateMatchModes[TemplateMatchModes["TM_SQDIFF"] = 0] = "TM_SQDIFF";
|
|
134
|
+
TemplateMatchModes[TemplateMatchModes["TM_SQDIFF_NORMED"] = 1] = "TM_SQDIFF_NORMED";
|
|
135
|
+
TemplateMatchModes[TemplateMatchModes["TM_CCORR"] = 2] = "TM_CCORR";
|
|
136
|
+
TemplateMatchModes[TemplateMatchModes["TM_CCORR_NORMED"] = 3] = "TM_CCORR_NORMED";
|
|
137
|
+
TemplateMatchModes[TemplateMatchModes["TM_CCOEFF"] = 4] = "TM_CCOEFF";
|
|
138
|
+
TemplateMatchModes[TemplateMatchModes["TM_CCOEFF_NORMED"] = 5] = "TM_CCOEFF_NORMED"; /*!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{
|
|
139
|
+
\sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2}
|
|
140
|
+
}\f] */
|
|
141
|
+
})(TemplateMatchModes || (exports.TemplateMatchModes = TemplateMatchModes = {}));
|
|
142
|
+
;
|
|
131
143
|
/**
|
|
132
144
|
* Represents the OpenCV class that provides image processing functionality.
|
|
133
145
|
*/
|
|
@@ -182,6 +194,13 @@ class OpenCV {
|
|
|
182
194
|
bgrToGray() {
|
|
183
195
|
return new OpenCV(bgrToGray(this.imageData));
|
|
184
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
199
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
200
|
+
*/
|
|
201
|
+
equalizeHist() {
|
|
202
|
+
return new OpenCV(equalizeHist(this.imageData));
|
|
203
|
+
}
|
|
185
204
|
/**
|
|
186
205
|
* Draws a rectangle on the image.
|
|
187
206
|
* @param start - The starting point of the rectangle.
|
package/dist/index.d.cts
CHANGED
|
@@ -78,6 +78,7 @@ export type Imwrite = (image: ImageData) => Buffer;
|
|
|
78
78
|
export type MatchTemplate = (image: ImageData, template: ImageData, method?: number | null, mask?: ImageData) => MatchData;
|
|
79
79
|
export type Blur = (image: ImageData, sizeX: number, sizeY: number) => ImageData;
|
|
80
80
|
export type BgrToGray = (image: ImageData) => ImageData;
|
|
81
|
+
export type EqualizeHist = (image: ImageData) => ImageData;
|
|
81
82
|
export type DrawRectangle = (image: ImageData, start: Point, end: Point, rgb: Color, thickness: number) => ImageData;
|
|
82
83
|
export type GetRegion = (image: ImageData, region: ROI) => ImageData;
|
|
83
84
|
export type TextRecognition = (trainedDataPath: string, dataLang: string, imagePath: string) => string;
|
|
@@ -168,6 +169,45 @@ declare class KeyboardListener {
|
|
|
168
169
|
*/
|
|
169
170
|
static destroy(): void;
|
|
170
171
|
}
|
|
172
|
+
export declare enum TemplateMatchModes {
|
|
173
|
+
TM_SQDIFF = 0,/*!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f]
|
|
174
|
+
with mask:
|
|
175
|
+
\f[R(x,y)= \sum _{x',y'} \left( (T(x',y')-I(x+x',y+y')) \cdot
|
|
176
|
+
M(x',y') \right)^2\f] */
|
|
177
|
+
TM_SQDIFF_NORMED = 1,/*!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{
|
|
178
|
+
x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
|
|
179
|
+
with mask:
|
|
180
|
+
\f[R(x,y)= \frac{\sum _{x',y'} \left( (T(x',y')-I(x+x',y+y')) \cdot
|
|
181
|
+
M(x',y') \right)^2}{\sqrt{\sum_{x',y'} \left( T(x',y') \cdot
|
|
182
|
+
M(x',y') \right)^2 \cdot \sum_{x',y'} \left( I(x+x',y+y') \cdot
|
|
183
|
+
M(x',y') \right)^2}}\f] */
|
|
184
|
+
TM_CCORR = 2,/*!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f]
|
|
185
|
+
with mask:
|
|
186
|
+
\f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y') \cdot M(x',y')
|
|
187
|
+
^2)\f] */
|
|
188
|
+
TM_CCORR_NORMED = 3,/*!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{
|
|
189
|
+
\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
|
|
190
|
+
with mask:
|
|
191
|
+
\f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y') \cdot
|
|
192
|
+
M(x',y')^2)}{\sqrt{\sum_{x',y'} \left( T(x',y') \cdot M(x',y')
|
|
193
|
+
\right)^2 \cdot \sum_{x',y'} \left( I(x+x',y+y') \cdot M(x',y')
|
|
194
|
+
\right)^2}}\f] */
|
|
195
|
+
TM_CCOEFF = 4,/*!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f]
|
|
196
|
+
where
|
|
197
|
+
\f[\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{
|
|
198
|
+
x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h)
|
|
199
|
+
\cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}\f]
|
|
200
|
+
with mask:
|
|
201
|
+
\f[\begin{array}{l} T'(x',y')=M(x',y') \cdot \left( T(x',y') -
|
|
202
|
+
\frac{1}{\sum _{x'',y''} M(x'',y'')} \cdot \sum _{x'',y''}
|
|
203
|
+
(T(x'',y'') \cdot M(x'',y'')) \right) \\ I'(x+x',y+y')=M(x',y')
|
|
204
|
+
\cdot \left( I(x+x',y+y') - \frac{1}{\sum _{x'',y''} M(x'',y'')}
|
|
205
|
+
\cdot \sum _{x'',y''} (I(x+x'',y+y'') \cdot M(x'',y'')) \right)
|
|
206
|
+
\end{array} \f] */
|
|
207
|
+
TM_CCOEFF_NORMED = 5 /*!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{
|
|
208
|
+
\sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2}
|
|
209
|
+
}\f] */
|
|
210
|
+
}
|
|
171
211
|
/**
|
|
172
212
|
* Represents the OpenCV class that provides image processing functionality.
|
|
173
213
|
*/
|
|
@@ -205,6 +245,11 @@ declare class OpenCV {
|
|
|
205
245
|
* @returns A new OpenCV instance with the grayscale image data.
|
|
206
246
|
*/
|
|
207
247
|
bgrToGray(): OpenCV;
|
|
248
|
+
/**
|
|
249
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
250
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
251
|
+
*/
|
|
252
|
+
equalizeHist(): OpenCV;
|
|
208
253
|
/**
|
|
209
254
|
* Draws a rectangle on the image.
|
|
210
255
|
* @param start - The starting point of the rectangle.
|
package/dist/index.d.mts
CHANGED
|
@@ -78,6 +78,7 @@ export type Imwrite = (image: ImageData) => Buffer;
|
|
|
78
78
|
export type MatchTemplate = (image: ImageData, template: ImageData, method?: number | null, mask?: ImageData) => MatchData;
|
|
79
79
|
export type Blur = (image: ImageData, sizeX: number, sizeY: number) => ImageData;
|
|
80
80
|
export type BgrToGray = (image: ImageData) => ImageData;
|
|
81
|
+
export type EqualizeHist = (image: ImageData) => ImageData;
|
|
81
82
|
export type DrawRectangle = (image: ImageData, start: Point, end: Point, rgb: Color, thickness: number) => ImageData;
|
|
82
83
|
export type GetRegion = (image: ImageData, region: ROI) => ImageData;
|
|
83
84
|
export type TextRecognition = (trainedDataPath: string, dataLang: string, imagePath: string) => string;
|
|
@@ -168,6 +169,45 @@ declare class KeyboardListener {
|
|
|
168
169
|
*/
|
|
169
170
|
static destroy(): void;
|
|
170
171
|
}
|
|
172
|
+
export declare enum TemplateMatchModes {
|
|
173
|
+
TM_SQDIFF = 0,/*!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f]
|
|
174
|
+
with mask:
|
|
175
|
+
\f[R(x,y)= \sum _{x',y'} \left( (T(x',y')-I(x+x',y+y')) \cdot
|
|
176
|
+
M(x',y') \right)^2\f] */
|
|
177
|
+
TM_SQDIFF_NORMED = 1,/*!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{
|
|
178
|
+
x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
|
|
179
|
+
with mask:
|
|
180
|
+
\f[R(x,y)= \frac{\sum _{x',y'} \left( (T(x',y')-I(x+x',y+y')) \cdot
|
|
181
|
+
M(x',y') \right)^2}{\sqrt{\sum_{x',y'} \left( T(x',y') \cdot
|
|
182
|
+
M(x',y') \right)^2 \cdot \sum_{x',y'} \left( I(x+x',y+y') \cdot
|
|
183
|
+
M(x',y') \right)^2}}\f] */
|
|
184
|
+
TM_CCORR = 2,/*!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f]
|
|
185
|
+
with mask:
|
|
186
|
+
\f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y') \cdot M(x',y')
|
|
187
|
+
^2)\f] */
|
|
188
|
+
TM_CCORR_NORMED = 3,/*!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{
|
|
189
|
+
\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
|
|
190
|
+
with mask:
|
|
191
|
+
\f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y') \cdot
|
|
192
|
+
M(x',y')^2)}{\sqrt{\sum_{x',y'} \left( T(x',y') \cdot M(x',y')
|
|
193
|
+
\right)^2 \cdot \sum_{x',y'} \left( I(x+x',y+y') \cdot M(x',y')
|
|
194
|
+
\right)^2}}\f] */
|
|
195
|
+
TM_CCOEFF = 4,/*!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f]
|
|
196
|
+
where
|
|
197
|
+
\f[\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{
|
|
198
|
+
x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h)
|
|
199
|
+
\cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}\f]
|
|
200
|
+
with mask:
|
|
201
|
+
\f[\begin{array}{l} T'(x',y')=M(x',y') \cdot \left( T(x',y') -
|
|
202
|
+
\frac{1}{\sum _{x'',y''} M(x'',y'')} \cdot \sum _{x'',y''}
|
|
203
|
+
(T(x'',y'') \cdot M(x'',y'')) \right) \\ I'(x+x',y+y')=M(x',y')
|
|
204
|
+
\cdot \left( I(x+x',y+y') - \frac{1}{\sum _{x'',y''} M(x'',y'')}
|
|
205
|
+
\cdot \sum _{x'',y''} (I(x+x'',y+y'') \cdot M(x'',y'')) \right)
|
|
206
|
+
\end{array} \f] */
|
|
207
|
+
TM_CCOEFF_NORMED = 5 /*!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{
|
|
208
|
+
\sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2}
|
|
209
|
+
}\f] */
|
|
210
|
+
}
|
|
171
211
|
/**
|
|
172
212
|
* Represents the OpenCV class that provides image processing functionality.
|
|
173
213
|
*/
|
|
@@ -205,6 +245,11 @@ declare class OpenCV {
|
|
|
205
245
|
* @returns A new OpenCV instance with the grayscale image data.
|
|
206
246
|
*/
|
|
207
247
|
bgrToGray(): OpenCV;
|
|
248
|
+
/**
|
|
249
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
250
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
251
|
+
*/
|
|
252
|
+
equalizeHist(): OpenCV;
|
|
208
253
|
/**
|
|
209
254
|
* Draws a rectangle on the image.
|
|
210
255
|
* @param start - The starting point of the rectangle.
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ const nodeGypBuild = __require("node-gyp-build");
|
|
|
8
8
|
import { keyCodes, KeyCodeHelper } from "./keyCodes.mjs";
|
|
9
9
|
import { __dirnameLocal } from "./dirnameLocal.mjs";
|
|
10
10
|
const bindings = nodeGypBuild(path.resolve(__dirnameLocal, ".."));
|
|
11
|
-
const { setKeyDownCallback, setKeyUpCallback, unsetKeyDownCallback, unsetKeyUpCallback, getWindowData, captureWindowN, captureScreenAsync, mouseMove, mouseClick, mouseDrag, typeString, pressKey, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, textRecognition } = bindings;
|
|
11
|
+
const { setKeyDownCallback, setKeyUpCallback, unsetKeyDownCallback, unsetKeyUpCallback, getWindowData, captureWindowN, captureScreenAsync, mouseMove, mouseClick, mouseDrag, typeString, pressKey, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, textRecognition, equalizeHist } = bindings;
|
|
12
12
|
const rawPressKey = pressKey;
|
|
13
13
|
/**
|
|
14
14
|
* Captures a window and saves it to a file.
|
|
@@ -109,6 +109,18 @@ class KeyboardListener {
|
|
|
109
109
|
unsetKeyUpCallback();
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
+
export var TemplateMatchModes;
|
|
113
|
+
(function (TemplateMatchModes) {
|
|
114
|
+
TemplateMatchModes[TemplateMatchModes["TM_SQDIFF"] = 0] = "TM_SQDIFF";
|
|
115
|
+
TemplateMatchModes[TemplateMatchModes["TM_SQDIFF_NORMED"] = 1] = "TM_SQDIFF_NORMED";
|
|
116
|
+
TemplateMatchModes[TemplateMatchModes["TM_CCORR"] = 2] = "TM_CCORR";
|
|
117
|
+
TemplateMatchModes[TemplateMatchModes["TM_CCORR_NORMED"] = 3] = "TM_CCORR_NORMED";
|
|
118
|
+
TemplateMatchModes[TemplateMatchModes["TM_CCOEFF"] = 4] = "TM_CCOEFF";
|
|
119
|
+
TemplateMatchModes[TemplateMatchModes["TM_CCOEFF_NORMED"] = 5] = "TM_CCOEFF_NORMED"; /*!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{
|
|
120
|
+
\sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2}
|
|
121
|
+
}\f] */
|
|
122
|
+
})(TemplateMatchModes || (TemplateMatchModes = {}));
|
|
123
|
+
;
|
|
112
124
|
/**
|
|
113
125
|
* Represents the OpenCV class that provides image processing functionality.
|
|
114
126
|
*/
|
|
@@ -163,6 +175,13 @@ class OpenCV {
|
|
|
163
175
|
bgrToGray() {
|
|
164
176
|
return new OpenCV(bgrToGray(this.imageData));
|
|
165
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
180
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
181
|
+
*/
|
|
182
|
+
equalizeHist() {
|
|
183
|
+
return new OpenCV(equalizeHist(this.imageData));
|
|
184
|
+
}
|
|
166
185
|
/**
|
|
167
186
|
* Draws a rectangle on the image.
|
|
168
187
|
* @param start - The starting point of the rectangle.
|
package/package.json
CHANGED
|
Binary file
|
package/src/cpp/main.cpp
CHANGED
|
@@ -26,6 +26,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
|
|
|
26
26
|
exports.Set("matchTemplate", Napi::Function::New(env, MatchTemplate));
|
|
27
27
|
exports.Set("blur", Napi::Function::New(env, Blur));
|
|
28
28
|
exports.Set("bgrToGray", Napi::Function::New(env, BgrToGray));
|
|
29
|
+
exports.Set("equalizeHist", Napi::Function::New(env, EqualizeHist));
|
|
29
30
|
exports.Set("drawRectangle", Napi::Function::New(env, DrawRectangle));
|
|
30
31
|
exports.Set("getRegion", Napi::Function::New(env, GetRegion));
|
|
31
32
|
exports.Set("textRecognition", Napi::Function::New(env, TextRecognition));
|
package/src/cpp/opencv.cpp
CHANGED
|
@@ -158,11 +158,11 @@ Napi::Value MatchTemplate(const Napi::CallbackInfo &info)
|
|
|
158
158
|
cv::Mat result;
|
|
159
159
|
if (mask.empty())
|
|
160
160
|
{
|
|
161
|
-
cv::matchTemplate(src, templ, result,
|
|
161
|
+
cv::matchTemplate(src, templ, result, method);
|
|
162
162
|
}
|
|
163
163
|
else
|
|
164
164
|
{
|
|
165
|
-
cv::matchTemplate(src, templ, result,
|
|
165
|
+
cv::matchTemplate(src, templ, result, method, mask);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
double minVal, maxVal;
|
|
@@ -234,6 +234,52 @@ Napi::Value BgrToGray(const Napi::CallbackInfo &info)
|
|
|
234
234
|
return result;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
Napi::Value EqualizeHist(const Napi::CallbackInfo &info)
|
|
238
|
+
{
|
|
239
|
+
Napi::Env env = info.Env();
|
|
240
|
+
|
|
241
|
+
if (info.Length() < 1 || !info[0].IsObject())
|
|
242
|
+
{
|
|
243
|
+
Napi::TypeError::New(env, "Invalid arguments. Expected: (object)").ThrowAsJavaScriptException();
|
|
244
|
+
return env.Null();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
Napi::Object srcObj = info[0].As<Napi::Object>();
|
|
248
|
+
|
|
249
|
+
if (!srcObj.Has("data") || !srcObj.Has("width") || !srcObj.Has("height"))
|
|
250
|
+
{
|
|
251
|
+
Napi::TypeError::New(env, "Invalid image data object. Expected properties: 'data', 'width', 'height'").ThrowAsJavaScriptException();
|
|
252
|
+
return env.Null();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (!srcObj.Get("data").IsTypedArray())
|
|
256
|
+
{
|
|
257
|
+
Napi::TypeError::New(env, "TypedArray expected for 'data' property").ThrowAsJavaScriptException();
|
|
258
|
+
return env.Null();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
int width = srcObj.Get("width").ToNumber().Int32Value();
|
|
262
|
+
int height = srcObj.Get("height").ToNumber().Int32Value();
|
|
263
|
+
|
|
264
|
+
cv::Mat src(height, width, CV_8UC1, srcObj.Get("data").As<Napi::TypedArray>().ArrayBuffer().Data());
|
|
265
|
+
cv::Mat dst;
|
|
266
|
+
|
|
267
|
+
cv::equalizeHist(src, dst);
|
|
268
|
+
|
|
269
|
+
Napi::Object result = Napi::Object::New(env);
|
|
270
|
+
size_t totalBytes = dst.total() * dst.elemSize();
|
|
271
|
+
Napi::ArrayBuffer arrayBuffer = Napi::ArrayBuffer::New(env, totalBytes);
|
|
272
|
+
Napi::Uint8Array uint8Array = Napi::Uint8Array::New(env, totalBytes, arrayBuffer, 0);
|
|
273
|
+
|
|
274
|
+
memcpy(uint8Array.Data(), dst.data, totalBytes);
|
|
275
|
+
result.Set("width", width);
|
|
276
|
+
result.Set("height", height);
|
|
277
|
+
result.Set("data", uint8Array);
|
|
278
|
+
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
|
|
237
283
|
Napi::Value Blur(const Napi::CallbackInfo &info)
|
|
238
284
|
{
|
|
239
285
|
Napi::Env env = info.Env();
|
package/src/index.mts
CHANGED
|
@@ -120,7 +120,7 @@ export type Blur = (
|
|
|
120
120
|
sizeY: number
|
|
121
121
|
) => ImageData;
|
|
122
122
|
export type BgrToGray = (image: ImageData) => ImageData;
|
|
123
|
-
|
|
123
|
+
export type EqualizeHist = (image: ImageData) => ImageData;
|
|
124
124
|
export type DrawRectangle = (
|
|
125
125
|
image: ImageData,
|
|
126
126
|
start: Point,
|
|
@@ -153,7 +153,8 @@ const {
|
|
|
153
153
|
bgrToGray,
|
|
154
154
|
drawRectangle,
|
|
155
155
|
getRegion,
|
|
156
|
-
textRecognition
|
|
156
|
+
textRecognition,
|
|
157
|
+
equalizeHist
|
|
157
158
|
}: {
|
|
158
159
|
setKeyDownCallback: SetKeyCallback;
|
|
159
160
|
setKeyUpCallback: SetKeyCallback;
|
|
@@ -175,6 +176,7 @@ const {
|
|
|
175
176
|
getRegion: GetRegion;
|
|
176
177
|
textRecognition: TextRecognition;
|
|
177
178
|
captureScreenAsync: CaptureScreenAsync;
|
|
179
|
+
equalizeHist: EqualizeHist
|
|
178
180
|
} = bindings;
|
|
179
181
|
|
|
180
182
|
const rawPressKey = pressKey;
|
|
@@ -324,6 +326,45 @@ class KeyboardListener {
|
|
|
324
326
|
}
|
|
325
327
|
}
|
|
326
328
|
|
|
329
|
+
export enum TemplateMatchModes {
|
|
330
|
+
TM_SQDIFF = 0, /*!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f]
|
|
331
|
+
with mask:
|
|
332
|
+
\f[R(x,y)= \sum _{x',y'} \left( (T(x',y')-I(x+x',y+y')) \cdot
|
|
333
|
+
M(x',y') \right)^2\f] */
|
|
334
|
+
TM_SQDIFF_NORMED = 1, /*!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{
|
|
335
|
+
x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
|
|
336
|
+
with mask:
|
|
337
|
+
\f[R(x,y)= \frac{\sum _{x',y'} \left( (T(x',y')-I(x+x',y+y')) \cdot
|
|
338
|
+
M(x',y') \right)^2}{\sqrt{\sum_{x',y'} \left( T(x',y') \cdot
|
|
339
|
+
M(x',y') \right)^2 \cdot \sum_{x',y'} \left( I(x+x',y+y') \cdot
|
|
340
|
+
M(x',y') \right)^2}}\f] */
|
|
341
|
+
TM_CCORR = 2, /*!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f]
|
|
342
|
+
with mask:
|
|
343
|
+
\f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y') \cdot M(x',y')
|
|
344
|
+
^2)\f] */
|
|
345
|
+
TM_CCORR_NORMED = 3, /*!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{
|
|
346
|
+
\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f]
|
|
347
|
+
with mask:
|
|
348
|
+
\f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y') \cdot
|
|
349
|
+
M(x',y')^2)}{\sqrt{\sum_{x',y'} \left( T(x',y') \cdot M(x',y')
|
|
350
|
+
\right)^2 \cdot \sum_{x',y'} \left( I(x+x',y+y') \cdot M(x',y')
|
|
351
|
+
\right)^2}}\f] */
|
|
352
|
+
TM_CCOEFF = 4, /*!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f]
|
|
353
|
+
where
|
|
354
|
+
\f[\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{
|
|
355
|
+
x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h)
|
|
356
|
+
\cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}\f]
|
|
357
|
+
with mask:
|
|
358
|
+
\f[\begin{array}{l} T'(x',y')=M(x',y') \cdot \left( T(x',y') -
|
|
359
|
+
\frac{1}{\sum _{x'',y''} M(x'',y'')} \cdot \sum _{x'',y''}
|
|
360
|
+
(T(x'',y'') \cdot M(x'',y'')) \right) \\ I'(x+x',y+y')=M(x',y')
|
|
361
|
+
\cdot \left( I(x+x',y+y') - \frac{1}{\sum _{x'',y''} M(x'',y'')}
|
|
362
|
+
\cdot \sum _{x'',y''} (I(x+x'',y+y'') \cdot M(x'',y'')) \right)
|
|
363
|
+
\end{array} \f] */
|
|
364
|
+
TM_CCOEFF_NORMED = 5 /*!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{
|
|
365
|
+
\sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2}
|
|
366
|
+
}\f] */
|
|
367
|
+
};
|
|
327
368
|
|
|
328
369
|
/**
|
|
329
370
|
* Represents the OpenCV class that provides image processing functionality.
|
|
@@ -385,6 +426,15 @@ class OpenCV {
|
|
|
385
426
|
return new OpenCV(bgrToGray(this.imageData));
|
|
386
427
|
}
|
|
387
428
|
|
|
429
|
+
/**
|
|
430
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
431
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
432
|
+
*/
|
|
433
|
+
equalizeHist() {
|
|
434
|
+
return new OpenCV(equalizeHist(this.imageData));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
|
|
388
438
|
/**
|
|
389
439
|
* Draws a rectangle on the image.
|
|
390
440
|
* @param start - The starting point of the rectangle.
|