Skip to content

Commit 895417e

Browse files
committed
(#57) Updated debug output to assure ROI does not exceed image boundaries
1 parent a364e0e commit 895417e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/provider/opencv/template-matching-finder.class.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ export class TemplateMatchingFinder implements FinderInterface {
103103

104104
private static async debugResult(image: cv.Mat, result: MatchResult, filename: string, suffix?: string) {
105105
const roiRect = new cv.Rect(
106-
result.location.left,
107-
result.location.top,
108-
result.location.width,
109-
result.location.height);
106+
Math.min(Math.max(result.location.left, 0), image.cols),
107+
Math.min(Math.max(result.location.top, 0), image.rows),
108+
Math.min(result.location.width, image.cols - result.location.left),
109+
Math.min(result.location.height, image.rows - result.location.top));
110110
this.debugImage(image.getRegion(roiRect), filename, suffix);
111111
}
112112

0 commit comments

Comments
 (0)