From dc9ee53ff5d7de050f2abdb2056ad0fe151aa951 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 1 Apr 2020 18:45:02 +0000 Subject: [PATCH] stitching: fix range check in DpSeamFinder::computeCosts --- modules/stitching/src/seam_finders.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/stitching/src/seam_finders.cpp b/modules/stitching/src/seam_finders.cpp index 1bc0e8e8e4..c8a320dc74 100644 --- a/modules/stitching/src/seam_finders.cpp +++ b/modules/stitching/src/seam_finders.cpp @@ -745,7 +745,9 @@ void DpSeamFinder::computeCosts( { for (int x = roi.x; x < roi.br().x+1; ++x) { - if (labels_(y, x) == l && x > 0 && labels_(y, x-1) == l) + if (x > 0 && x < labels_.cols && + labels_(y, x) == l && labels_(y, x-1) == l + ) { float costColor = (diff(image1, y + dy1, x + dx1 - 1, image2, y + dy2, x + dx2) + diff(image1, y + dy1, x + dx1, image2, y + dy2, x + dx2 - 1)) / 2; @@ -769,7 +771,9 @@ void DpSeamFinder::computeCosts( { for (int x = roi.x; x < roi.br().x; ++x) { - if (labels_(y, x) == l && y > 0 && labels_(y-1, x) == l) + if (y > 0 && y < labels_.rows && + labels_(y, x) == l && labels_(y-1, x) == l + ) { float costColor = (diff(image1, y + dy1 - 1, x + dx1, image2, y + dy2, x + dx2) + diff(image1, y + dy1, x + dx1, image2, y + dy2 - 1, x + dx2)) / 2;