Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@udarrr/template-matcher

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@udarrr/template-matcher - npm Package Compare versions

Comparing version 4.1.2 to 4.1.3

189

dist/lib/handlers/invariantRotating.js

@@ -6,9 +6,10 @@ "use strict";

// All rights reserved.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvariantRotatingHandler = void 0;
const opencv4nodejs_prebuilt_install_1 = __importDefault(require("opencv4nodejs-prebuilt-install"));
const opencv4nodejs_prebuilt_install_2 = require("opencv4nodejs-prebuilt-install");
let cv;
try {
cv = require('opencv4nodejs-prebuilt-install');
}
catch (_a) { }
const opencv4nodejs_prebuilt_install_1 = require("opencv4nodejs-prebuilt-install");
class InvariantRotatingHandler {

@@ -27,9 +28,9 @@ static GetTopLayer(matTempl, iMinDstLength) {

const dAngle_radian = dAngle * InvariantRotatingHandler.D2R;
const ptC = new opencv4nodejs_prebuilt_install_2.Point2((matSrc.cols - 1) / 2.0, (matSrc.rows - 1) / 2.0);
const ptLT_rotate = InvariantRotatingHandler.ptRotatePt2f(ptLT, ptC, dAngle_radian).sub(new opencv4nodejs_prebuilt_install_2.Point2(3, 3));
const ptC = new opencv4nodejs_prebuilt_install_1.Point2((matSrc.cols - 1) / 2.0, (matSrc.rows - 1) / 2.0);
const ptLT_rotate = InvariantRotatingHandler.ptRotatePt2f(ptLT, ptC, dAngle_radian).sub(new opencv4nodejs_prebuilt_install_1.Point2(3, 3));
const sizePadding = { width: size.width + 6, height: size.height + 6 };
const rMat = opencv4nodejs_prebuilt_install_1.default.getRotationMatrix2D(ptC, dAngle, 1);
const rMat = cv.getRotationMatrix2D(ptC, dAngle, 1);
rMat.set(0, 2, rMat.at(0, 2) - ptLT_rotate.x);
rMat.set(1, 2, rMat.at(1, 2) - ptLT_rotate.y);
return await matSrc.warpAffineAsync(rMat, new opencv4nodejs_prebuilt_install_2.Size(sizePadding.width, sizePadding.height));
return await matSrc.warpAffineAsync(rMat, new opencv4nodejs_prebuilt_install_1.Size(sizePadding.width, sizePadding.height));
}

@@ -61,3 +62,3 @@ static async Match(matSrc, matDst, iMinDstLength, dScore = 0.8, rotationRange = 180, dMaxOverlap = 0, debug = false) {

const iTopSrcH = vecMatSrcPyr[iTopLayer].rows;
const ptCenter = new opencv4nodejs_prebuilt_install_2.Point2((iTopSrcW - 1) / 2.0, (iTopSrcH - 1) / 2.0);
const ptCenter = new opencv4nodejs_prebuilt_install_1.Point2((iTopSrcW - 1) / 2.0, (iTopSrcH - 1) / 2.0);
let vecMatchParameter = [];

@@ -70,3 +71,3 @@ const vecLayerScore = [...Array(iTopLayer + 1).keys()].fill(dScore);

for (let i = 0; i < vecAngles.length; i++) {
let matR = opencv4nodejs_prebuilt_install_1.default.getRotationMatrix2D(ptCenter, vecAngles[i], 1);
let matR = cv.getRotationMatrix2D(ptCenter, vecAngles[i], 1);
let sizeBest = InvariantRotatingHandler.GetBestRotationSize({ width: vecMatSrcPyr[iTopLayer].cols, height: vecMatSrcPyr[iTopLayer].rows }, { width: pTemplData.vecPyramid[iTopLayer].cols, height: pTemplData.vecPyramid[iTopLayer].rows }, vecAngles[i]);

@@ -77,6 +78,6 @@ let fTranslationX = (sizeBest.width - 1) / 2.0 - ptCenter.x;

matR.set(1, 2, matR.at(1, 2) + fTranslationY);
const matRotatedSrc = await vecMatSrcPyr[iTopLayer].warpAffineAsync(matR, new opencv4nodejs_prebuilt_install_2.Size(sizeBest.width, sizeBest.height), opencv4nodejs_prebuilt_install_2.INTER_LINEAR, opencv4nodejs_prebuilt_install_2.BORDER_CONSTANT, new opencv4nodejs_prebuilt_install_2.Vec3(pTemplData.iBorderColor, pTemplData.iBorderColor, pTemplData.iBorderColor));
const matRotatedSrc = await vecMatSrcPyr[iTopLayer].warpAffineAsync(matR, new opencv4nodejs_prebuilt_install_1.Size(sizeBest.width, sizeBest.height), opencv4nodejs_prebuilt_install_1.INTER_LINEAR, opencv4nodejs_prebuilt_install_1.BORDER_CONSTANT, new opencv4nodejs_prebuilt_install_1.Vec3(pTemplData.iBorderColor, pTemplData.iBorderColor, pTemplData.iBorderColor));
const matResult = await InvariantRotatingHandler.MatchTemplate(matRotatedSrc, pTemplData, iTopLayer);
if (bCalMaxByBlock) {
const blockMax = new SBlockMax(matResult, new opencv4nodejs_prebuilt_install_2.Size(pTemplData.vecPyramid[iTopLayer].cols, pTemplData.vecPyramid[iTopLayer].rows));
const blockMax = new SBlockMax(matResult, new opencv4nodejs_prebuilt_install_1.Size(pTemplData.vecPyramid[iTopLayer].cols, pTemplData.vecPyramid[iTopLayer].rows));
const minMaxLoc = blockMax.GetMaxValueLoc();

@@ -88,4 +89,4 @@ let nextMaxLoc = { srcMat: matResult, minMaxLoc: minMaxLoc };

vecMatchParameter.push({
pt: new opencv4nodejs_prebuilt_install_2.Point2(nextMaxLoc.minMaxLoc.ptMaxLoc.x - fTranslationX, nextMaxLoc.minMaxLoc.ptMaxLoc.y - fTranslationY),
size: new opencv4nodejs_prebuilt_install_2.Size(pTemplData.vecPyramid[iTopLayer].cols, pTemplData.vecPyramid[iTopLayer].rows),
pt: new opencv4nodejs_prebuilt_install_1.Point2(nextMaxLoc.minMaxLoc.ptMaxLoc.x - fTranslationX, nextMaxLoc.minMaxLoc.ptMaxLoc.y - fTranslationY),
size: new opencv4nodejs_prebuilt_install_1.Size(pTemplData.vecPyramid[iTopLayer].cols, pTemplData.vecPyramid[iTopLayer].rows),
dMatchScore: nextMaxLoc.minMaxLoc.dMaxVal,

@@ -95,3 +96,3 @@ dMatchAngle: vecAngles[i],

for (let j = 0; j < m_iMaxPos + InvariantRotatingHandler.MATCH_CANDIDATE_NUM - 1; j++) {
nextMaxLoc = await InvariantRotatingHandler.GetNextMaxLocBlock(matResult, nextMaxLoc.minMaxLoc.ptMaxLoc, new opencv4nodejs_prebuilt_install_2.Size(pTemplData.vecPyramid[iTopLayer].cols, pTemplData.vecPyramid[iTopLayer].rows), m_dMaxOverlap, blockMax);
nextMaxLoc = await InvariantRotatingHandler.GetNextMaxLocBlock(matResult, nextMaxLoc.minMaxLoc.ptMaxLoc, new opencv4nodejs_prebuilt_install_1.Size(pTemplData.vecPyramid[iTopLayer].cols, pTemplData.vecPyramid[iTopLayer].rows), m_dMaxOverlap, blockMax);
if (nextMaxLoc.minMaxLoc.dMaxVal < vecLayerScore[iTopLayer]) {

@@ -101,4 +102,4 @@ break;

vecMatchParameter.push({
pt: new opencv4nodejs_prebuilt_install_2.Point2(nextMaxLoc.minMaxLoc.ptMaxLoc.x - fTranslationX, nextMaxLoc.minMaxLoc.ptMaxLoc.y - fTranslationY),
size: new opencv4nodejs_prebuilt_install_2.Size(pTemplData.vecPyramid[iTopLayer].cols, pTemplData.vecPyramid[iTopLayer].rows),
pt: new opencv4nodejs_prebuilt_install_1.Point2(nextMaxLoc.minMaxLoc.ptMaxLoc.x - fTranslationX, nextMaxLoc.minMaxLoc.ptMaxLoc.y - fTranslationY),
size: new opencv4nodejs_prebuilt_install_1.Size(pTemplData.vecPyramid[iTopLayer].cols, pTemplData.vecPyramid[iTopLayer].rows),
dMatchScore: nextMaxLoc.minMaxLoc.dMaxVal,

@@ -110,3 +111,3 @@ dMatchAngle: vecAngles[i],

else {
let minMaxLoc = await opencv4nodejs_prebuilt_install_1.default.minMaxLocAsync(matResult);
let minMaxLoc = await cv.minMaxLocAsync(matResult);
if (minMaxLoc.maxVal < vecLayerScore[iTopLayer]) {

@@ -116,3 +117,3 @@ continue;

vecMatchParameter.push({
pt: new opencv4nodejs_prebuilt_install_2.Point2(minMaxLoc.maxLoc.x - fTranslationX, minMaxLoc.maxLoc.y - fTranslationY),
pt: new opencv4nodejs_prebuilt_install_1.Point2(minMaxLoc.maxLoc.x - fTranslationX, minMaxLoc.maxLoc.y - fTranslationY),
dMatchScore: minMaxLoc.maxVal,

@@ -129,3 +130,3 @@ dMatchAngle: vecAngles[i],

vecMatchParameter.push({
pt: new opencv4nodejs_prebuilt_install_2.Point2(nextMaxLoc.minMaxLoc.maxLoc.x - fTranslationX, nextMaxLoc.minMaxLoc.maxLoc.y - fTranslationY),
pt: new opencv4nodejs_prebuilt_install_1.Point2(nextMaxLoc.minMaxLoc.maxLoc.x - fTranslationX, nextMaxLoc.minMaxLoc.maxLoc.y - fTranslationY),
dMatchScore: nextMaxLoc.minMaxLoc.maxVal,

@@ -173,3 +174,3 @@ dMatchAngle: vecAngles[i],

}
const ptSrcCenter = new opencv4nodejs_prebuilt_install_2.Point2((vecMatSrcPyr[iLayer].cols - 1) / 2.0, (vecMatSrcPyr[iLayer].rows - 1) / 2.0);
const ptSrcCenter = new opencv4nodejs_prebuilt_install_1.Point2((vecMatSrcPyr[iLayer].cols - 1) / 2.0, (vecMatSrcPyr[iLayer].rows - 1) / 2.0);
const vecNewMatchParameter = [];

@@ -179,3 +180,3 @@ let iMaxScoreIndex = 0;

for (let j = 0; j < vecAngles.length; j++) {
const matRotatedSrc = await InvariantRotatingHandler.GetRotatedROI(vecMatSrcPyr[iLayer], new opencv4nodejs_prebuilt_install_2.Size(pTemplData.vecPyramid[iLayer].cols, pTemplData.vecPyramid[iLayer].rows), ptLT.mul(2), vecAngles[j]);
const matRotatedSrc = await InvariantRotatingHandler.GetRotatedROI(vecMatSrcPyr[iLayer], new opencv4nodejs_prebuilt_install_1.Size(pTemplData.vecPyramid[iLayer].cols, pTemplData.vecPyramid[iLayer].rows), ptLT.mul(2), vecAngles[j]);
const matResult = await InvariantRotatingHandler.MatchTemplate(matRotatedSrc, pTemplData, iLayer);

@@ -197,3 +198,3 @@ const minMax = matResult.minMaxLoc();

for (let x = -1; x <= 1; x++) {
const ptMaxLocTemp = ptMaxLoc.add(new opencv4nodejs_prebuilt_install_2.Point2(x, y));
const ptMaxLocTemp = ptMaxLoc.add(new opencv4nodejs_prebuilt_install_1.Point2(x, y));
vecNewMatchParameter[j].vecResult[x + 1][y + 1] = matResult.at(ptMaxLocTemp.y, ptMaxLocTemp.x);

@@ -208,4 +209,4 @@ }

const dNewMatchAngle = vecNewMatchParameter[iMaxScoreIndex].dMatchAngle;
const ptPaddingLT = InvariantRotatingHandler.ptRotatePt2f(ptLT.mul(2), ptSrcCenter, dNewMatchAngle * InvariantRotatingHandler.D2R).sub(new opencv4nodejs_prebuilt_install_2.Point2(3, 3));
let pt = new opencv4nodejs_prebuilt_install_2.Point2(vecNewMatchParameter[iMaxScoreIndex].pt.x + ptPaddingLT.x, vecNewMatchParameter[iMaxScoreIndex].pt.y + ptPaddingLT.y);
const ptPaddingLT = InvariantRotatingHandler.ptRotatePt2f(ptLT.mul(2), ptSrcCenter, dNewMatchAngle * InvariantRotatingHandler.D2R).sub(new opencv4nodejs_prebuilt_install_1.Point2(3, 3));
let pt = new opencv4nodejs_prebuilt_install_1.Point2(vecNewMatchParameter[iMaxScoreIndex].pt.x + ptPaddingLT.x, vecNewMatchParameter[iMaxScoreIndex].pt.y + ptPaddingLT.y);
pt = InvariantRotatingHandler.ptRotatePt2f(pt, ptSrcCenter, -dNewMatchAngle * InvariantRotatingHandler.D2R);

@@ -235,7 +236,7 @@ if (iLayer == iStopLayer) {

ptLT = vecAllResult[i].pt;
ptRT = new opencv4nodejs_prebuilt_install_2.Point2(ptLT.x + iDstW * Math.cos(dRAngle), ptLT.y - iDstW * Math.sin(dRAngle));
ptLB = new opencv4nodejs_prebuilt_install_2.Point2(ptLT.x + iDstH * Math.sin(dRAngle), ptLT.y + iDstH * Math.cos(dRAngle));
ptRB = new opencv4nodejs_prebuilt_install_2.Point2(ptRT.x + iDstH * Math.sin(dRAngle), ptRT.y + iDstH * Math.cos(dRAngle));
ptRT = new opencv4nodejs_prebuilt_install_1.Point2(ptLT.x + iDstW * Math.cos(dRAngle), ptLT.y - iDstW * Math.sin(dRAngle));
ptLB = new opencv4nodejs_prebuilt_install_1.Point2(ptLT.x + iDstH * Math.sin(dRAngle), ptLT.y + iDstH * Math.cos(dRAngle));
ptRB = new opencv4nodejs_prebuilt_install_1.Point2(ptRT.x + iDstH * Math.sin(dRAngle), ptRT.y + iDstH * Math.cos(dRAngle));
const rotatedRectPoint = InvariantRotatingHandler.RotatedRect(ptLT, ptRT, ptRB);
vecAllResult[i].rectR = new opencv4nodejs_prebuilt_install_2.RotatedRect(rotatedRectPoint.center, rotatedRectPoint.size, rotatedRectPoint.angle);
vecAllResult[i].rectR = new opencv4nodejs_prebuilt_install_1.RotatedRect(rotatedRectPoint.center, rotatedRectPoint.size, rotatedRectPoint.angle);
}

@@ -248,7 +249,7 @@ vecAllResult = InvariantRotatingHandler.FilterWithRotatedRect(vecAllResult, 'CV_TM_CCOEFF_NORMED', m_dMaxOverlap);

let sstm = {
ptLT: new opencv4nodejs_prebuilt_install_2.Point2(0, 0),
ptRT: new opencv4nodejs_prebuilt_install_2.Point2(0, 0),
ptRB: new opencv4nodejs_prebuilt_install_2.Point2(0, 0),
ptLB: new opencv4nodejs_prebuilt_install_2.Point2(0, 0),
ptCenter: new opencv4nodejs_prebuilt_install_2.Point2(0, 0),
ptLT: new opencv4nodejs_prebuilt_install_1.Point2(0, 0),
ptRT: new opencv4nodejs_prebuilt_install_1.Point2(0, 0),
ptRB: new opencv4nodejs_prebuilt_install_1.Point2(0, 0),
ptLB: new opencv4nodejs_prebuilt_install_1.Point2(0, 0),
ptCenter: new opencv4nodejs_prebuilt_install_1.Point2(0, 0),
dMatchedAngle: 0,

@@ -260,6 +261,6 @@ dMatchScore: 0,

sstm.ptLT = vecAllResult[i].pt;
sstm.ptRT = new opencv4nodejs_prebuilt_install_2.Point2(sstm.ptLT.x + iW * Math.cos(dRAngle), sstm.ptLT.y - iW * Math.sin(dRAngle));
sstm.ptLB = new opencv4nodejs_prebuilt_install_2.Point2(sstm.ptLT.x + iH * Math.sin(dRAngle), sstm.ptLT.y + iH * Math.cos(dRAngle));
sstm.ptRB = new opencv4nodejs_prebuilt_install_2.Point2(sstm.ptRT.x + iH * Math.sin(dRAngle), sstm.ptRT.y + iH * Math.cos(dRAngle));
sstm.ptCenter = new opencv4nodejs_prebuilt_install_2.Point2((sstm.ptLT.x + sstm.ptRT.x + sstm.ptRB.x + sstm.ptLB.x) / 4, (sstm.ptLT.y + sstm.ptRT.y + sstm.ptRB.y + sstm.ptLB.y) / 4);
sstm.ptRT = new opencv4nodejs_prebuilt_install_1.Point2(sstm.ptLT.x + iW * Math.cos(dRAngle), sstm.ptLT.y - iW * Math.sin(dRAngle));
sstm.ptLB = new opencv4nodejs_prebuilt_install_1.Point2(sstm.ptLT.x + iH * Math.sin(dRAngle), sstm.ptLT.y + iH * Math.cos(dRAngle));
sstm.ptRB = new opencv4nodejs_prebuilt_install_1.Point2(sstm.ptRT.x + iH * Math.sin(dRAngle), sstm.ptRT.y + iH * Math.cos(dRAngle));
sstm.ptCenter = new opencv4nodejs_prebuilt_install_1.Point2((sstm.ptLT.x + sstm.ptRT.x + sstm.ptRB.x + sstm.ptLB.x) / 4, (sstm.ptLT.y + sstm.ptRT.y + sstm.ptRB.y + sstm.ptLB.y) / 4);
sstm.dMatchedAngle = -vecAllResult[i].dMatchAngle;

@@ -297,15 +298,15 @@ sstm.dMatchScore = vecAllResult[i].dMatchScore;

}
matSrc.drawLine(sstm.ptLT, sstm.ptLT.add(ptDis1.div(2)), new opencv4nodejs_prebuilt_install_2.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptLT, sstm.ptLT.add(ptDis2.div(2)), new opencv4nodejs_prebuilt_install_2.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptRT, sstm.ptRT.add(ptDis1.div(2)), new opencv4nodejs_prebuilt_install_2.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptRT, sstm.ptRT.sub(ptDis2.div(2)), new opencv4nodejs_prebuilt_install_2.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptRB, sstm.ptRB.sub(ptDis1.div(2)), new opencv4nodejs_prebuilt_install_2.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptRB, sstm.ptRB.sub(ptDis2.div(2)), new opencv4nodejs_prebuilt_install_2.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptLB, sstm.ptLB.sub(ptDis1.div(2)), new opencv4nodejs_prebuilt_install_2.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptLB, sstm.ptLB.add(ptDis2.div(2)), new opencv4nodejs_prebuilt_install_2.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine((_b = sstm.ptCenter) === null || _b === void 0 ? void 0 : _b.sub(new opencv4nodejs_prebuilt_install_2.Point2(5, 0)), (_c = sstm.ptCenter) === null || _c === void 0 ? void 0 : _c.add(new opencv4nodejs_prebuilt_install_2.Point2(5, 0)), new opencv4nodejs_prebuilt_install_2.Vec3(255, 0, 0), 2);
matSrc.drawLine((_d = sstm.ptCenter) === null || _d === void 0 ? void 0 : _d.sub(new opencv4nodejs_prebuilt_install_2.Point2(0, 5)), (_e = sstm.ptCenter) === null || _e === void 0 ? void 0 : _e.add(new opencv4nodejs_prebuilt_install_2.Point2(0, 5)), new opencv4nodejs_prebuilt_install_2.Vec3(255, 0, 0), 2);
matSrc.drawLine(sstm.ptLT, sstm.ptLT.add(ptDis1.div(2)), new opencv4nodejs_prebuilt_install_1.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptLT, sstm.ptLT.add(ptDis2.div(2)), new opencv4nodejs_prebuilt_install_1.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptRT, sstm.ptRT.add(ptDis1.div(2)), new opencv4nodejs_prebuilt_install_1.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptRT, sstm.ptRT.sub(ptDis2.div(2)), new opencv4nodejs_prebuilt_install_1.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptRB, sstm.ptRB.sub(ptDis1.div(2)), new opencv4nodejs_prebuilt_install_1.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptRB, sstm.ptRB.sub(ptDis2.div(2)), new opencv4nodejs_prebuilt_install_1.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptLB, sstm.ptLB.sub(ptDis1.div(2)), new opencv4nodejs_prebuilt_install_1.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine(sstm.ptLB, sstm.ptLB.add(ptDis2.div(2)), new opencv4nodejs_prebuilt_install_1.Vec3(0, 255, 0), 1, 16);
matSrc.drawLine((_b = sstm.ptCenter) === null || _b === void 0 ? void 0 : _b.sub(new opencv4nodejs_prebuilt_install_1.Point2(5, 0)), (_c = sstm.ptCenter) === null || _c === void 0 ? void 0 : _c.add(new opencv4nodejs_prebuilt_install_1.Point2(5, 0)), new opencv4nodejs_prebuilt_install_1.Vec3(255, 0, 0), 2);
matSrc.drawLine((_d = sstm.ptCenter) === null || _d === void 0 ? void 0 : _d.sub(new opencv4nodejs_prebuilt_install_1.Point2(0, 5)), (_e = sstm.ptCenter) === null || _e === void 0 ? void 0 : _e.add(new opencv4nodejs_prebuilt_install_1.Point2(0, 5)), new opencv4nodejs_prebuilt_install_1.Vec3(255, 0, 0), 2);
}
opencv4nodejs_prebuilt_install_1.default.imshow('debug', matSrc);
opencv4nodejs_prebuilt_install_1.default.waitKey(0);
cv.imshow('debug', matSrc);
cv.waitKey(0);
}

@@ -321,4 +322,4 @@ return m_vecSingleTargetData;

return {
center: new opencv4nodejs_prebuilt_install_2.Point2(cx, cy),
size: new opencv4nodejs_prebuilt_install_2.Size(width, height),
center: new opencv4nodejs_prebuilt_install_1.Point2(cx, cy),
size: new opencv4nodejs_prebuilt_install_1.Size(width, height),
angle: angle,

@@ -442,3 +443,3 @@ };

let bottomLeft = { x: x + (-w / 2) * cos - (h / 2) * sin, y: y + (-w / 2) * sin + (h / 2) * cos };
return [new opencv4nodejs_prebuilt_install_2.Point2(topLeft.x, topLeft.y), new opencv4nodejs_prebuilt_install_2.Point2(topRight.x, topRight.y), new opencv4nodejs_prebuilt_install_2.Point2(bottomRight.x, bottomRight.y), new opencv4nodejs_prebuilt_install_2.Point2(bottomLeft.x, bottomLeft.y)];
return [new opencv4nodejs_prebuilt_install_1.Point2(topLeft.x, topLeft.y), new opencv4nodejs_prebuilt_install_1.Point2(topRight.x, topRight.y), new opencv4nodejs_prebuilt_install_1.Point2(bottomRight.x, bottomRight.y), new opencv4nodejs_prebuilt_install_1.Point2(bottomLeft.x, bottomLeft.y)];
}

@@ -471,3 +472,3 @@ function isPointInside(point, polygon) {

let intersectionY = a.y + ua * (b.y - a.y);
return new opencv4nodejs_prebuilt_install_2.Point2(intersectionX, intersectionY);
return new opencv4nodejs_prebuilt_install_1.Point2(intersectionX, intersectionY);
}

@@ -532,4 +533,4 @@ }

const iStartY = ptMaxLoc.y - sizeTemplate.height * (1 - dMaxOverlap);
matResult.drawRectangle(new opencv4nodejs_prebuilt_install_2.Rect(iStartX, iStartY, 2 * sizeTemplate.width * (1 - dMaxOverlap), 2 * sizeTemplate.height * (1 - dMaxOverlap)), new opencv4nodejs_prebuilt_install_2.Vec3(-1, -1, -1), opencv4nodejs_prebuilt_install_2.FILLED);
const ptNewMaxLoc = await opencv4nodejs_prebuilt_install_1.default.minMaxLocAsync(matResult);
matResult.drawRectangle(new opencv4nodejs_prebuilt_install_1.Rect(iStartX, iStartY, 2 * sizeTemplate.width * (1 - dMaxOverlap), 2 * sizeTemplate.height * (1 - dMaxOverlap)), new opencv4nodejs_prebuilt_install_1.Vec3(-1, -1, -1), opencv4nodejs_prebuilt_install_1.FILLED);
const ptNewMaxLoc = await cv.minMaxLocAsync(matResult);
return { srcMat: matResult, minMaxLoc: ptNewMaxLoc };

@@ -540,4 +541,4 @@ }

let iStartY = Math.floor(ptMaxLoc.y - sizeTemplate.height * (1 - dMaxOverlap));
const rectIgnore = new opencv4nodejs_prebuilt_install_2.Rect(iStartX, iStartY, Math.floor(2 * sizeTemplate.width * (1 - dMaxOverlap)), Math.floor(2 * sizeTemplate.height * (1 - dMaxOverlap)));
matResult.drawRectangle(rectIgnore, new opencv4nodejs_prebuilt_install_2.Vec3(-1, -1, -1), opencv4nodejs_prebuilt_install_2.FILLED);
const rectIgnore = new opencv4nodejs_prebuilt_install_1.Rect(iStartX, iStartY, Math.floor(2 * sizeTemplate.width * (1 - dMaxOverlap)), Math.floor(2 * sizeTemplate.height * (1 - dMaxOverlap)));
matResult.drawRectangle(rectIgnore, new opencv4nodejs_prebuilt_install_1.Vec3(-1, -1, -1), opencv4nodejs_prebuilt_install_1.FILLED);
blockMax.UpdateMax(rectIgnore);

@@ -599,3 +600,3 @@ const ptReturn = blockMax.GetMaxValueLoc();

static async MatchTemplate(matSrc, pTemplData, iLayer, method = 'TM_CCORR') {
const result = await matSrc.matchTemplateAsync(pTemplData.vecPyramid[iLayer], opencv4nodejs_prebuilt_install_1.default[method]);
const result = await matSrc.matchTemplateAsync(pTemplData.vecPyramid[iLayer], cv[method]);
return await InvariantRotatingHandler.CCOEFF_Denominator(matSrc, pTemplData, result, iLayer);

@@ -605,3 +606,3 @@ }

if (pTemplData.vecResultEqual1[iLayer]) {
await matResult.setToAsync(new opencv4nodejs_prebuilt_install_2.Vec3(1, 1, 1));
await matResult.setToAsync(new opencv4nodejs_prebuilt_install_1.Vec3(1, 1, 1));
return matResult;

@@ -611,3 +612,3 @@ }

let sqsum;
const integral = await matSrc.integralAsync(opencv4nodejs_prebuilt_install_2.CV_64F);
const integral = await matSrc.integralAsync(opencv4nodejs_prebuilt_install_1.CV_64F);
sum = integral.sum;

@@ -662,3 +663,3 @@ sqsum = integral.sqsum;

// return matResult;
return new opencv4nodejs_prebuilt_install_2.Mat(matResultArr, opencv4nodejs_prebuilt_install_2.CV_32F);
return new opencv4nodejs_prebuilt_install_1.Mat(matResultArr, opencv4nodejs_prebuilt_install_1.CV_32F);
}

@@ -670,6 +671,6 @@ static async LearnPattern(matDst, iMinDstLength) {

templData.vecPyramid = pyramid;
templData.iBorderColor = opencv4nodejs_prebuilt_install_1.default.mean(matDst).w < 128 ? 255 : 0;
templData.iBorderColor = cv.mean(matDst).w < 128 ? 255 : 0;
for (let i = 0; i < templData.vecPyramid.length; i++) {
const invArea = 1 / (templData.vecPyramid[i].rows * templData.vecPyramid[i].cols);
let templMeanAndSdv = opencv4nodejs_prebuilt_install_1.default.meanStdDev(templData.vecPyramid[i]);
let templMeanAndSdv = cv.meanStdDev(templData.vecPyramid[i]);
let templNorm = templMeanAndSdv.stddev.at(0, 0) * templMeanAndSdv.stddev.at(0, 0);

@@ -695,7 +696,7 @@ if (templNorm < Number.EPSILON) {

const ptRT = { x: sizeSrc.width - 1, y: 0 };
const ptCenter = new opencv4nodejs_prebuilt_install_2.Point2((sizeSrc.width - 1) / 2.0, (sizeSrc.height - 1) / 2.0);
const ptLT_R = InvariantRotatingHandler.ptRotatePt2f(new opencv4nodejs_prebuilt_install_2.Point2(ptLT.x, ptLT.y), ptCenter, dRAngle * InvariantRotatingHandler.D2R);
const ptLB_R = InvariantRotatingHandler.ptRotatePt2f(new opencv4nodejs_prebuilt_install_2.Point2(ptLB.x, ptLB.y), ptCenter, dRAngle * InvariantRotatingHandler.D2R);
const ptRB_R = InvariantRotatingHandler.ptRotatePt2f(new opencv4nodejs_prebuilt_install_2.Point2(ptRB.x, ptRB.y), ptCenter, dRAngle * InvariantRotatingHandler.D2R);
const ptRT_R = InvariantRotatingHandler.ptRotatePt2f(new opencv4nodejs_prebuilt_install_2.Point2(ptRT.x, ptRT.y), ptCenter, dRAngle * InvariantRotatingHandler.D2R);
const ptCenter = new opencv4nodejs_prebuilt_install_1.Point2((sizeSrc.width - 1) / 2.0, (sizeSrc.height - 1) / 2.0);
const ptLT_R = InvariantRotatingHandler.ptRotatePt2f(new opencv4nodejs_prebuilt_install_1.Point2(ptLT.x, ptLT.y), ptCenter, dRAngle * InvariantRotatingHandler.D2R);
const ptLB_R = InvariantRotatingHandler.ptRotatePt2f(new opencv4nodejs_prebuilt_install_1.Point2(ptLB.x, ptLB.y), ptCenter, dRAngle * InvariantRotatingHandler.D2R);
const ptRB_R = InvariantRotatingHandler.ptRotatePt2f(new opencv4nodejs_prebuilt_install_1.Point2(ptRB.x, ptRB.y), ptCenter, dRAngle * InvariantRotatingHandler.D2R);
const ptRT_R = InvariantRotatingHandler.ptRotatePt2f(new opencv4nodejs_prebuilt_install_1.Point2(ptRT.x, ptRT.y), ptCenter, dRAngle * InvariantRotatingHandler.D2R);
const fTopY = Math.max(ptLT_R.y, ptLB_R.y, ptRB_R.y, ptRT_R.y);

@@ -750,3 +751,3 @@ const fBottomY = Math.min(ptLT_R.y, ptLB_R.y, ptRB_R.y, ptRT_R.y);

dY = -dY + dHeight;
return new opencv4nodejs_prebuilt_install_2.Point2(dX, dY);
return new opencv4nodejs_prebuilt_install_1.Point2(dX, dY);
}

@@ -777,3 +778,3 @@ }

for (let i = 0; i < iCol * iRow; i++) {
this.vecBlock.push({ rect: new opencv4nodejs_prebuilt_install_2.Rect(), dMax: 0, ptMaxLoc: new opencv4nodejs_prebuilt_install_2.Point2(0, 0) });
this.vecBlock.push({ rect: new opencv4nodejs_prebuilt_install_1.Rect(), dMax: 0, ptMaxLoc: new opencv4nodejs_prebuilt_install_1.Point2(0, 0) });
}

@@ -783,8 +784,8 @@ let iCount = 0;

for (let x = 0; x < iCol; x++) {
const rectBlock = new opencv4nodejs_prebuilt_install_2.Rect(x * iBlockW, y * iBlockH, iBlockW, iBlockH);
const rectBlock = new opencv4nodejs_prebuilt_install_1.Rect(x * iBlockW, y * iBlockH, iBlockW, iBlockH);
this.vecBlock[iCount].rect = rectBlock;
const minMax = opencv4nodejs_prebuilt_install_1.default.minMaxLoc(matSrc.getRegion(rectBlock));
const minMax = cv.minMaxLoc(matSrc.getRegion(rectBlock));
this.vecBlock[iCount].dMax = minMax.maxVal;
this.vecBlock[iCount].ptMaxLoc = minMax.maxLoc;
this.vecBlock[iCount].ptMaxLoc = this.vecBlock[iCount].ptMaxLoc.add(new opencv4nodejs_prebuilt_install_2.Point2(rectBlock.x, rectBlock.y));
this.vecBlock[iCount].ptMaxLoc = this.vecBlock[iCount].ptMaxLoc.add(new opencv4nodejs_prebuilt_install_1.Point2(rectBlock.x, rectBlock.y));
iCount++;

@@ -794,37 +795,37 @@ }

if (bHResidue && bVResidue) {
const rectRight = new opencv4nodejs_prebuilt_install_2.Rect(iCol * iBlockW, 0, matSrc.cols - iCol * iBlockW, matSrc.rows);
const maxMin = opencv4nodejs_prebuilt_install_1.default.minMaxLoc(matSrc.getRegion(rectRight));
let blockRight = { dMax: 0, rect: new opencv4nodejs_prebuilt_install_2.Rect(), ptMaxLoc: new opencv4nodejs_prebuilt_install_2.Point2(0, 0) };
const rectRight = new opencv4nodejs_prebuilt_install_1.Rect(iCol * iBlockW, 0, matSrc.cols - iCol * iBlockW, matSrc.rows);
const maxMin = cv.minMaxLoc(matSrc.getRegion(rectRight));
let blockRight = { dMax: 0, rect: new opencv4nodejs_prebuilt_install_1.Rect(), ptMaxLoc: new opencv4nodejs_prebuilt_install_1.Point2(0, 0) };
blockRight.dMax = maxMin.maxVal;
blockRight.rect = rectRight;
blockRight.ptMaxLoc = maxMin.maxLoc;
blockRight.ptMaxLoc = blockRight.ptMaxLoc.add(new opencv4nodejs_prebuilt_install_2.Point2(rectRight.x, rectRight.y));
blockRight.ptMaxLoc = blockRight.ptMaxLoc.add(new opencv4nodejs_prebuilt_install_1.Point2(rectRight.x, rectRight.y));
this.vecBlock.push(blockRight);
const rectBottom = new opencv4nodejs_prebuilt_install_2.Rect(0, iRow * iBlockH, iCol * iBlockW, matSrc.rows - iRow * iBlockH);
const maxMin2 = opencv4nodejs_prebuilt_install_1.default.minMaxLoc(matSrc.getRegion(rectBottom));
let blockBottom = { dMax: 0, rect: new opencv4nodejs_prebuilt_install_2.Rect(), ptMaxLoc: new opencv4nodejs_prebuilt_install_2.Point2(0, 0) };
const rectBottom = new opencv4nodejs_prebuilt_install_1.Rect(0, iRow * iBlockH, iCol * iBlockW, matSrc.rows - iRow * iBlockH);
const maxMin2 = cv.minMaxLoc(matSrc.getRegion(rectBottom));
let blockBottom = { dMax: 0, rect: new opencv4nodejs_prebuilt_install_1.Rect(), ptMaxLoc: new opencv4nodejs_prebuilt_install_1.Point2(0, 0) };
blockBottom.dMax = maxMin2.maxVal;
blockBottom.rect = rectBottom;
blockBottom.ptMaxLoc = maxMin2.maxLoc;
blockBottom.ptMaxLoc = blockBottom.ptMaxLoc.add(new opencv4nodejs_prebuilt_install_2.Point2(rectBottom.x, rectBottom.y));
blockBottom.ptMaxLoc = blockBottom.ptMaxLoc.add(new opencv4nodejs_prebuilt_install_1.Point2(rectBottom.x, rectBottom.y));
this.vecBlock.push(blockBottom);
}
else if (bHResidue) {
const rectRight = new opencv4nodejs_prebuilt_install_2.Rect(iCol * iBlockW, 0, matSrc.cols - iCol * iBlockW, matSrc.rows);
const maxMin = opencv4nodejs_prebuilt_install_1.default.minMaxLoc(matSrc.getRegion(rectRight));
let blockRight = { dMax: 0, rect: new opencv4nodejs_prebuilt_install_2.Rect(), ptMaxLoc: new opencv4nodejs_prebuilt_install_2.Point2(0, 0) };
const rectRight = new opencv4nodejs_prebuilt_install_1.Rect(iCol * iBlockW, 0, matSrc.cols - iCol * iBlockW, matSrc.rows);
const maxMin = cv.minMaxLoc(matSrc.getRegion(rectRight));
let blockRight = { dMax: 0, rect: new opencv4nodejs_prebuilt_install_1.Rect(), ptMaxLoc: new opencv4nodejs_prebuilt_install_1.Point2(0, 0) };
blockRight.dMax = maxMin.maxVal;
blockRight.rect = rectRight;
blockRight.ptMaxLoc = maxMin.maxLoc;
blockRight.ptMaxLoc = blockRight.ptMaxLoc.add(new opencv4nodejs_prebuilt_install_2.Point2(rectRight.x, rectRight.y));
blockRight.ptMaxLoc = blockRight.ptMaxLoc.add(new opencv4nodejs_prebuilt_install_1.Point2(rectRight.x, rectRight.y));
this.vecBlock.push(blockRight);
}
else {
const rectBottom = new opencv4nodejs_prebuilt_install_2.Rect(0, iRow * iBlockH, matSrc.cols, matSrc.rows - iRow * iBlockH);
const maxMin2 = opencv4nodejs_prebuilt_install_1.default.minMaxLoc(matSrc.getRegion(rectBottom));
let blockBottom = { dMax: 0, rect: new opencv4nodejs_prebuilt_install_2.Rect(), ptMaxLoc: new opencv4nodejs_prebuilt_install_2.Point2(0, 0) };
const rectBottom = new opencv4nodejs_prebuilt_install_1.Rect(0, iRow * iBlockH, matSrc.cols, matSrc.rows - iRow * iBlockH);
const maxMin2 = cv.minMaxLoc(matSrc.getRegion(rectBottom));
let blockBottom = { dMax: 0, rect: new opencv4nodejs_prebuilt_install_1.Rect(), ptMaxLoc: new opencv4nodejs_prebuilt_install_1.Point2(0, 0) };
blockBottom.dMax = maxMin2.maxVal;
blockBottom.rect = rectBottom;
blockBottom.ptMaxLoc = maxMin2.maxLoc;
blockBottom.ptMaxLoc = blockBottom.ptMaxLoc.add(new opencv4nodejs_prebuilt_install_2.Point2(rectBottom.x, rectBottom.y));
blockBottom.ptMaxLoc = blockBottom.ptMaxLoc.add(new opencv4nodejs_prebuilt_install_1.Point2(rectBottom.x, rectBottom.y));
this.vecBlock.push(blockBottom);

@@ -845,6 +846,6 @@ }

}
const minMax = opencv4nodejs_prebuilt_install_1.default.minMaxLoc(this.matSrc.getRegion(this.vecBlock[i].rect));
const minMax = cv.minMaxLoc(this.matSrc.getRegion(this.vecBlock[i].rect));
this.vecBlock[i].dMax = minMax.maxVal;
this.vecBlock[i].ptMaxLoc = minMax.maxLoc;
this.vecBlock[i].ptMaxLoc = this.vecBlock[i].ptMaxLoc.add(new opencv4nodejs_prebuilt_install_2.Point2(this.vecBlock[i].rect.x, this.vecBlock[i].rect.y));
this.vecBlock[i].ptMaxLoc = this.vecBlock[i].ptMaxLoc.add(new opencv4nodejs_prebuilt_install_1.Point2(this.vecBlock[i].rect.x, this.vecBlock[i].rect.y));
}

@@ -856,3 +857,3 @@ }

if (iSize == 0) {
const maxMin = opencv4nodejs_prebuilt_install_1.default.minMaxLoc(this.matSrc);
const maxMin = cv.minMaxLoc(this.matSrc);
dMax = maxMin.maxVal;

@@ -859,0 +860,0 @@ ptMaxLoc = maxMin.maxLoc;

{
"name": "@udarrr/template-matcher",
"version": "4.1.2",
"version": "4.1.3",
"main": "dist/index",

@@ -5,0 +5,0 @@ "typings": "dist/index",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc