Skip to content

Commit

Permalink
Fixed a crash in RANSACProposer when the refmainder of image_size / c…
Browse files Browse the repository at this point in the history
…ell_size = 1.
  • Loading branch information
t-taniai committed Sep 4, 2017
1 parent 091b2b2 commit efe3ba5
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions LocalExpansionStereo/LayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class LayerManager
void addLayer(int unitRegionSize)
{
Layer layer;

#if 0
// This produces cells with irregular (smaller) sizes at left and bottom boundaries.
layer.regionUnitSize = unitRegionSize;
layer.heightBlocks = (height / unitRegionSize) + ((height % unitRegionSize) ? 1 : 0);
layer.widthBlocks = (width / unitRegionSize) + ((width % unitRegionSize) ? 1 : 0);
Expand Down Expand Up @@ -82,6 +85,85 @@ class LayerManager
filterRegion = filterRegion & imageDomain;
}
}
#else
// Make bigger cells by merging smaller ones at the right and bottom boundaries
// if the edge cells are smaller than "minsize".

layer.regionUnitSize = unitRegionSize;
int minsize = std::max(2, unitRegionSize / 2);
int frac_h = height % unitRegionSize;
int frac_w = width % unitRegionSize;
int split_h = frac_h >= minsize ? 1 : 0;
int split_w = frac_w >= minsize ? 1 : 0;

layer.heightBlocks = (height / unitRegionSize) + split_h;
layer.widthBlocks = (width / unitRegionSize) + split_w;

layer.sharedRegions.resize(layer.heightBlocks * layer.widthBlocks);
layer.filterRegions.resize(layer.heightBlocks * layer.widthBlocks);
layer.unitRegions.resize(layer.heightBlocks * layer.widthBlocks);

layer.disjointRegionSets.resize(16);
cv::Rect imageDomain(0, 0, width, height);

#pragma omp parallel for
for (int i = 0; i < layer.heightBlocks; i++) {
for (int j = 0; j < layer.widthBlocks; j++) {
int r = i*layer.widthBlocks + j;
cv::Rect &sharedRegion = layer.sharedRegions[r];
cv::Rect &filterRegion = layer.filterRegions[r];
cv::Rect &unitRegion = layer.unitRegions[r];

unitRegion.x = j * unitRegionSize;
unitRegion.y = i * unitRegionSize;
unitRegion.width = unitRegionSize;
unitRegion.height = unitRegionSize;
unitRegion = unitRegion & imageDomain;

sharedRegion.x = (j - 1) * unitRegionSize;
sharedRegion.y = (i - 1) * unitRegionSize;
sharedRegion.width = unitRegionSize * 3;
sharedRegion.height = unitRegionSize * 3;
sharedRegion = sharedRegion & imageDomain;

filterRegion.x = (j - 1) * unitRegionSize - windowR;
filterRegion.y = (i - 1) * unitRegionSize - windowR;
filterRegion.width = unitRegionSize * 3 + windowR * 2;
filterRegion.height = unitRegionSize * 3 + windowR * 2;
filterRegion = filterRegion & imageDomain;
}
}

// Fix sizes of regions near left and bottom boundaries to include fractional regions.
if (split_w == 0)
{
for (int i = 0; i < layer.heightBlocks; i++) {
int x1 = i*layer.widthBlocks + layer.widthBlocks - 1;
layer.unitRegions[x1].width += frac_w;
// sharedRegion and filterRegion have already correct sizes by their definition.
}
for (int i = 0; i < layer.heightBlocks; i++) {
int x1 = i*layer.widthBlocks + layer.widthBlocks - 2;
layer.sharedRegions[x1].width += frac_w;
layer.filterRegions[x1].width += frac_w;
layer.filterRegions[x1] = layer.filterRegions[x1] & imageDomain;
}
}
if (split_h == 0)
{
for (int j = 0; j < layer.widthBlocks; j++) {
int y1 = (layer.heightBlocks - 1)*layer.widthBlocks + j;
layer.unitRegions[y1].height += frac_h;
// sharedRegion and filterRegion have already correct sizes by their definition.
}
for (int j = 0; j < layer.widthBlocks; j++) {
int y1 = (layer.heightBlocks - 2)*layer.widthBlocks + j;
layer.sharedRegions[y1].height += frac_h;
layer.filterRegions[y1].height += frac_h;
layer.filterRegions[y1] = layer.filterRegions[y1] & imageDomain;
}
}
#endif

for ( int i = 0; i < layer.heightBlocks; i++ ){
for ( int j = 0; j < layer.widthBlocks; j++ ){
Expand Down

0 comments on commit efe3ba5

Please sign in to comment.