Skip to content

Commit dc9ee53

Browse files
committed
stitching: fix range check in DpSeamFinder::computeCosts
1 parent 396f43d commit dc9ee53

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

modules/stitching/src/seam_finders.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,9 @@ void DpSeamFinder::computeCosts(
745745
{
746746
for (int x = roi.x; x < roi.br().x+1; ++x)
747747
{
748-
if (labels_(y, x) == l && x > 0 && labels_(y, x-1) == l)
748+
if (x > 0 && x < labels_.cols &&
749+
labels_(y, x) == l && labels_(y, x-1) == l
750+
)
749751
{
750752
float costColor = (diff(image1, y + dy1, x + dx1 - 1, image2, y + dy2, x + dx2) +
751753
diff(image1, y + dy1, x + dx1, image2, y + dy2, x + dx2 - 1)) / 2;
@@ -769,7 +771,9 @@ void DpSeamFinder::computeCosts(
769771
{
770772
for (int x = roi.x; x < roi.br().x; ++x)
771773
{
772-
if (labels_(y, x) == l && y > 0 && labels_(y-1, x) == l)
774+
if (y > 0 && y < labels_.rows &&
775+
labels_(y, x) == l && labels_(y-1, x) == l
776+
)
773777
{
774778
float costColor = (diff(image1, y + dy1 - 1, x + dx1, image2, y + dy2, x + dx2) +
775779
diff(image1, y + dy1, x + dx1, image2, y + dy2 - 1, x + dx2)) / 2;

0 commit comments

Comments
 (0)