@@ -513,6 +513,7 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2,
513
513
6: r=(1, -dy*2)
514
514
7: r=(2, -dy)
515
515
*/
516
+
516
517
for ( x = x1; x != x2; x += dx )
517
518
{
518
519
int xm = x*NR2, xd = xm*D2;
@@ -853,6 +854,7 @@ TODO: Don't forget to rewrire this commentaries after
853
854
disp2cost also has the same size as img1 (or img2).
854
855
It contains the minimum current cost, used to find the best disparity, corresponding to the minimal cost.
855
856
*/
857
+ #include < stdio.h> // TODO: DUBUG!!!
856
858
static void computeDisparitySGBMParallel ( const Mat& img1, const Mat& img2,
857
859
Mat& disp1, const StereoSGBMParams& params,
858
860
Mat& buffer )
@@ -1005,7 +1007,7 @@ static void computeDisparitySGBMParallel( const Mat& img1, const Mat& img2,
1005
1007
if ( y > 0 ) // 4e: We calculate horizontal sums and forming full block sums for y coord by adding this horsums to previous line's sums and subtracting stored lowest
1006
1008
{ // 4e: horsum in hsumBuf. Exception is case y=0, where we need many iterations per lines to create full blocking sum.
1007
1009
const CostType* hsumSub = hsumBuf + (std::max (y - SH2 - 1 , 0 ) % hsumBufNRows)*costBufSize;
1008
- const CostType* Cprev = !fullDP || y == 0 ? C : C - costBufSize; // 4e: Well, actually y>0, so we don't need this check: y==0
1010
+ const CostType* Cprev = C - costBufSize; // 4e: Well, actually y>0, so we don't need this check: y==0
1009
1011
1010
1012
for ( x = D; x < width1*D; x += D )
1011
1013
{
@@ -1089,11 +1091,11 @@ static void computeDisparitySGBMParallel( const Mat& img1, const Mat& img2,
1089
1091
6: r=(1, -dy*2)
1090
1092
7: r=(2, -dy)
1091
1093
*/
1092
- for ( x = 0 ; x != width ; x++ )
1094
+ for ( x = 0 ; x != width1 ; x++ )
1093
1095
{
1094
1096
int xd = x*D2;
1095
1097
1096
- int delta = minLr[1 ][x];
1098
+ int delta = minLr[1 ][x] + P2 ;
1097
1099
1098
1100
CostType* Lr_ppr = Lr[1 ] + xd;
1099
1101
@@ -1189,9 +1191,9 @@ static void computeDisparitySGBMParallel( const Mat& img1, const Mat& img2,
1189
1191
L = Cpd + std::min ((int )Lr_ppr[d], std::min (Lr_ppr[d-1 ] + P1, std::min (Lr_ppr[d+1 ] + P1, delta))) - delta;
1190
1192
1191
1193
Lr_p[d] = (CostType)L;
1192
- minL0 = std::min (minL, L);
1194
+ minL = std::min (minL, L);
1193
1195
1194
- Sp[d] = saturate_cast<CostType>(Sp[d] + L0 );
1196
+ Sp[d] = saturate_cast<CostType>(Sp[d] + L );
1195
1197
}
1196
1198
minLr[0 ][x] = (CostType)minL;
1197
1199
}
@@ -1224,16 +1226,16 @@ static void computeDisparitySGBMParallel( const Mat& img1, const Mat& img2,
1224
1226
{
1225
1227
int x, d;
1226
1228
DispType* disp1ptr = disp1.ptr <DispType>(y);
1227
- CostType* C = Cbuf + costBufSize;
1228
- CostType* S = Sbuf + costBufSize;
1229
+ CostType* C = Cbuf + y* costBufSize;
1230
+ CostType* S = Sbuf + y* costBufSize;
1229
1231
1230
1232
for ( x = 0 ; x < width; x++ )
1231
1233
{
1232
1234
disp1ptr[x] = disp2ptr[x] = (DispType)INVALID_DISP_SCALED;
1233
1235
disp2cost[x] = MAX_COST;
1234
1236
}
1235
1237
1236
- // clear the left and the right borders //TODO: Well, two of that memsets we could delete, but rest of them is direction-dependent
1238
+ // clear the left and the right borders
1237
1239
memset ( Lr - D2*LrBorder - 8 , 0 , D2*LrBorder*sizeof (CostType) ); // 4e: To understand this "8" shifts and how they could work it's simpler to imagine pixel dislocation in memory
1238
1240
memset ( Lr + width1*D2 - 8 , 0 , D2*LrBorder*sizeof (CostType) ); // 4e: ...00000000|D2-16 of real costs value(and some of them are zeroes too)|00000000...
1239
1241
memset ( minLr - LrBorder, 0 , LrBorder*sizeof (CostType) );
@@ -1261,7 +1263,7 @@ static void computeDisparitySGBMParallel( const Mat& img1, const Mat& img2,
1261
1263
{
1262
1264
int xd = x*D2;
1263
1265
1264
- int delta = minLr[x - 1 ];
1266
+ int delta = minLr[x - 1 ] + P2 ;
1265
1267
1266
1268
CostType* Lr_ppr = Lr + xd - D2;
1267
1269
@@ -1354,22 +1356,22 @@ static void computeDisparitySGBMParallel( const Mat& img1, const Mat& img2,
1354
1356
{
1355
1357
int Cpd = Cp[d], L; // 4e: Remember, that every Cp is increased on P2 in line number 369. That's why next 4 lines are paper-like actually
1356
1358
1357
- L0 = Cpd + std::min ((int )Lr_ppr[d], std::min (Lr_ppr[d-1 ] + P1, std::min (Lr_ppr[d+1 ] + P1, delta))) - delta;
1359
+ L = Cpd + std::min ((int )Lr_ppr[d], std::min (Lr_ppr[d-1 ] + P1, std::min (Lr_ppr[d+1 ] + P1, delta))) - delta;
1358
1360
1359
1361
Lr_p[d] = (CostType)L;
1360
- minL0 = std::min (minL, L);
1362
+ minL = std::min (minL, L);
1361
1363
1362
1364
Sp[d] = saturate_cast<CostType>(Sp[d] + L);
1363
1365
}
1364
- minLr[x] = (CostType)minL0 ;
1366
+ minLr[x] = (CostType)minL ;
1365
1367
}
1366
1368
}
1367
1369
1368
1370
for ( x = width1-1 ; x != -1 ; x--)
1369
1371
{
1370
1372
int xd = x*D2;
1371
1373
1372
- int delta = minLr[x + 1 ];
1374
+ int delta = minLr[x + 1 ] + P2 ;
1373
1375
1374
1376
CostType* Lr_ppr = Lr + xd + D2;
1375
1377
@@ -1489,10 +1491,10 @@ static void computeDisparitySGBMParallel( const Mat& img1, const Mat& img2,
1489
1491
{
1490
1492
int Cpd = Cp[d], L; // 4e: Remember, that every Cp is increased on P2 in line number 369. That's why next 4 lines are paper-like actually
1491
1493
1492
- L0 = Cpd + std::min ((int )Lr_ppr[d], std::min (Lr_ppr[d-1 ] + P1, std::min (Lr_ppr[d+1 ] + P1, delta))) - delta;
1494
+ L = Cpd + std::min ((int )Lr_ppr[d], std::min (Lr_ppr[d-1 ] + P1, std::min (Lr_ppr[d+1 ] + P1, delta))) - delta;
1493
1495
1494
1496
Lr_p[d] = (CostType)L;
1495
- minL0 = std::min (minL, L);
1497
+ minL = std::min (minL, L);
1496
1498
1497
1499
Sp[d] = saturate_cast<CostType>(Sp[d] + L);
1498
1500
if ( Sp[d] < minS )
@@ -1501,7 +1503,7 @@ static void computeDisparitySGBMParallel( const Mat& img1, const Mat& img2,
1501
1503
bestDisp = d;
1502
1504
}
1503
1505
}
1504
- minLr[x] = (CostType)minL0 ;
1506
+ minLr[x] = (CostType)minL ;
1505
1507
}
1506
1508
// Some postprocessing procedures and saving
1507
1509
for ( d = 0 ; d < D; d++ )
@@ -2206,6 +2208,8 @@ class StereoSGBMImpl : public StereoSGBM
2206
2208
2207
2209
if (params.mode ==MODE_SGBM_3WAY)
2208
2210
computeDisparity3WaySGBM ( left, right, disp, params, buffers, num_stripes );
2211
+ else if (params.mode ==MODE_HH4)
2212
+ computeDisparitySGBMParallel ( left, right, disp, params, buffer );
2209
2213
else
2210
2214
computeDisparitySGBM ( left, right, disp, params, buffer );
2211
2215
0 commit comments