@@ -1055,19 +1055,28 @@ void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64(const KeyPoint& kpt, f
1055
1055
y2 = fRound (sample_y + 0 .5f );
1056
1056
x2 = fRound (sample_x + 0 .5f );
1057
1057
1058
+ // fix crash: indexing with out-of-bounds index, this might happen near the edges of image
1059
+ // clip values so they fit into the image
1060
+ const MatSize& size = evolution[level].Lx .size ;
1061
+ y1 = min (max (0 , y1), size[0 ] - 1 );
1062
+ x1 = min (max (0 , x1), size[1 ] - 1 );
1063
+ y2 = min (max (0 , y2), size[0 ] - 1 );
1064
+ x2 = min (max (0 , x2), size[1 ] - 1 );
1065
+ CV_DbgAssert (evolution[level].Lx .size == evolution[level].Ly .size );
1066
+
1058
1067
fx = sample_x - x1;
1059
1068
fy = sample_y - y1;
1060
1069
1061
- res1 = *(evolution[level].Lx .ptr <float >(y1)+x1 );
1062
- res2 = *(evolution[level].Lx .ptr <float >(y1)+x2 );
1063
- res3 = *(evolution[level].Lx .ptr <float >(y2)+x1 );
1064
- res4 = *(evolution[level].Lx .ptr <float >(y2)+x2 );
1070
+ res1 = *(evolution[level].Lx .ptr <float >(y1, x1) );
1071
+ res2 = *(evolution[level].Lx .ptr <float >(y1, x2) );
1072
+ res3 = *(evolution[level].Lx .ptr <float >(y2, x1) );
1073
+ res4 = *(evolution[level].Lx .ptr <float >(y2, x2) );
1065
1074
rx = (1 .0f - fx)*(1 .0f - fy)*res1 + fx*(1 .0f - fy)*res2 + (1 .0f - fx)*fy*res3 + fx*fy*res4;
1066
1075
1067
- res1 = *(evolution[level].Ly .ptr <float >(y1)+x1 );
1068
- res2 = *(evolution[level].Ly .ptr <float >(y1)+x2 );
1069
- res3 = *(evolution[level].Ly .ptr <float >(y2)+x1 );
1070
- res4 = *(evolution[level].Ly .ptr <float >(y2)+x2 );
1076
+ res1 = *(evolution[level].Ly .ptr <float >(y1, x1) );
1077
+ res2 = *(evolution[level].Ly .ptr <float >(y1, x2) );
1078
+ res3 = *(evolution[level].Ly .ptr <float >(y2, x1) );
1079
+ res4 = *(evolution[level].Ly .ptr <float >(y2, x2) );
1071
1080
ry = (1 .0f - fx)*(1 .0f - fy)*res1 + fx*(1 .0f - fy)*res2 + (1 .0f - fx)*fy*res3 + fx*fy*res4;
1072
1081
1073
1082
// Get the x and y derivatives on the rotated axis
0 commit comments