Skip to content

Commit 10afb84

Browse files
committed
(#68) Turned a few anonymous functions into named ones
1 parent 6116f70 commit 10afb84

7 files changed

+23
-23
lines changed
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { MatchRequest } from "../../match-request.class";
22
import { Region } from "../../region.class";
33

4-
export const determineScaledSearchRegion = (matchRequest: MatchRequest): Region => {
4+
export function determineScaledSearchRegion(matchRequest: MatchRequest): Region {
55
const searchRegion = matchRequest.searchRegion;
66
const scaleX = matchRequest.haystack.pixelDensity.scaleX || 1.0;
77
const scaleY = matchRequest.haystack.pixelDensity.scaleY || 1.0;
88
searchRegion.width *= scaleX;
99
searchRegion.height *= scaleY;
1010
return searchRegion;
11-
};
11+
}

Diff for: lib/provider/opencv/find-edges.function.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as cv from "opencv4nodejs-prebuilt";
22

3-
export const findEdges = async (image: cv.Mat): Promise<cv.Mat> => {
3+
export async function findEdges(image: cv.Mat): Promise<cv.Mat> {
44
const gray = await image.cvtColorAsync(cv.COLOR_BGR2GRAY);
55
return gray.cannyAsync(50, 200);
6-
};
6+
}

Diff for: lib/provider/opencv/image-processor.class.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import * as cv from "opencv4nodejs-prebuilt";
22
import { Image } from "../../image.class";
33
import { Region } from "../../region.class";
44

5-
const determineROI = (img: Image, roi: Region): cv.Rect => {
5+
function determineROI(img: Image, roi: Region): cv.Rect {
66
return new cv.Rect(
77
Math.min(Math.max(roi.left, 0), img.width),
88
Math.min(Math.max(roi.top, 0), img.height),
99
Math.min(roi.width, img.width - roi.left),
1010
Math.min(roi.height, img.height - roi.top));
11-
};
11+
}
1212

1313
export class ImageProcessor {
1414
/**

Diff for: lib/provider/opencv/match-image.function.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as cv from "opencv4nodejs-prebuilt";
22
import { MatchResult } from "../../match-result.class";
33
import { Region } from "../../region.class";
44

5-
export const matchImages = async (haystack: cv.Mat, needle: cv.Mat): Promise<MatchResult> => {
5+
export async function matchImages(haystack: cv.Mat, needle: cv.Mat): Promise<MatchResult> {
66
const match = await haystack.matchTemplateAsync(
77
needle,
88
cv.TM_SQDIFF_NORMED,
@@ -17,4 +17,4 @@ export const matchImages = async (haystack: cv.Mat, needle: cv.Mat): Promise<Mat
1717
needle.rows,
1818
),
1919
);
20-
};
20+
}

Diff for: lib/provider/opencv/scale-image.function.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as cv from "opencv4nodejs-prebuilt";
22
import { lowerBound } from "./bound-value.function";
33

4-
export const scaleImage = async (image: cv.Mat, scaleFactor: number): Promise<cv.Mat> => {
4+
export async function scaleImage(image: cv.Mat, scaleFactor: number): Promise<cv.Mat> {
55
const boundScaleFactor = lowerBound(scaleFactor, 0.0, 1.0);
66
const scaledRows = Math.floor(image.rows * boundScaleFactor);
77
const scaledCols = Math.floor(image.cols * boundScaleFactor);
88
return image.resizeAsync(scaledRows, scaledCols, 0, 0, cv.INTER_AREA);
9-
};
9+
}

Diff for: lib/provider/opencv/scale-location.function.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { Region } from "../../region.class";
22
import { lowerBound } from "./bound-value.function";
33

4-
export const scaleLocation = (
4+
export function scaleLocation(
55
result: Region,
66
scaleFactor: number,
7-
): Region => {
7+
): Region {
88
const boundScaleFactor = lowerBound(scaleFactor, 0.0, 1.0);
99
return new Region(
1010
result.left / boundScaleFactor,
1111
result.top / boundScaleFactor,
1212
result.width,
1313
result.height,
1414
);
15-
};
15+
}

Diff for: lib/provider/opencv/template-matching-finder.class.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import { matchImages } from "./match-image.function";
1414
import { scaleImage } from "./scale-image.function";
1515
import { scaleLocation } from "./scale-location.function";
1616

17-
const loadNeedle = async (image: Image): Promise<cv.Mat> => {
17+
async function loadNeedle(image: Image): Promise<cv.Mat> {
1818
if (image.hasAlphaChannel) {
1919
return ImageProcessor.fromImageWithAlphaChannel(image);
2020
}
2121
return ImageProcessor.fromImageWithoutAlphaChannel(image);
22-
};
22+
}
2323

24-
const loadHaystack = async (matchRequest: MatchRequest): Promise<cv.Mat> => {
24+
async function loadHaystack(matchRequest: MatchRequest): Promise<cv.Mat> {
2525
const searchRegion = determineScaledSearchRegion(matchRequest);
2626
if (matchRequest.haystack.hasAlphaChannel) {
2727
return ImageProcessor.fromImageWithAlphaChannel(
@@ -34,9 +34,9 @@ const loadHaystack = async (matchRequest: MatchRequest): Promise<cv.Mat> => {
3434
searchRegion,
3535
);
3636
}
37-
};
37+
}
3838

39-
const debugImage = (image: cv.Mat, filename: string, suffix?: string) => {
39+
function debugImage(image: cv.Mat, filename: string, suffix?: string) {
4040
const parsedPath = path.parse(filename);
4141
let fullFilename = parsedPath.name;
4242
if (suffix) {
@@ -45,20 +45,20 @@ const debugImage = (image: cv.Mat, filename: string, suffix?: string) => {
4545
fullFilename += parsedPath.ext;
4646
const fullPath = path.join(parsedPath.dir, fullFilename);
4747
cv.imwriteAsync(fullPath, image);
48-
};
48+
}
4949

50-
// const debugResult = (image: cv.Mat, result: MatchResult, filename: string, suffix?: string) => {
50+
// function debugResult(image: cv.Mat, result: MatchResult, filename: string, suffix?: string) {
5151
// const roiRect = new cv.Rect(
5252
// Math.min(Math.max(result.location.left, 0), image.cols),
5353
// Math.min(Math.max(result.location.top, 0), image.rows),
5454
// Math.min(result.location.width, image.cols - result.location.left),
5555
// Math.min(result.location.height, image.rows - result.location.top));
5656
// debugImage(image.getRegion(roiRect), filename, suffix);
57-
// };
57+
// }
5858

59-
const isValidSearch = (needle: cv.Mat, haystack: cv.Mat): boolean => {
59+
function isValidSearch(needle: cv.Mat, haystack: cv.Mat): boolean {
6060
return (needle.cols <= haystack.cols) && (needle.rows <= haystack.rows);
61-
};
61+
}
6262

6363
export class TemplateMatchingFinder implements FinderInterface {
6464
private initialScale = [1.0];

0 commit comments

Comments
 (0)