Skip to content

Commit c231472

Browse files
committed
Merge pull request opencv#10290 from tomoaki0705:fixVS2012Round
2 parents 74f1295 + ecb6bcf commit c231472

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

modules/dnn/src/layers/pooling_layer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ namespace cv
5757
{
5858
namespace dnn
5959
{
60+
static inline int scaleAndRoundRoi(float f, float scale)
61+
{
62+
return (int)(f * scale + (f >= 0.f ? 0.5f : -0.5f));
63+
}
6064

6165
class PoolingLayerImpl : public PoolingLayer
6266
{
@@ -295,16 +299,16 @@ class PoolingLayerImpl : public PoolingLayer
295299
if (poolingType == ROI)
296300
{
297301
const float *roisData = rois->ptr<float>(n);
298-
int ystartROI = round(roisData[2] * spatialScale);
299-
int yendROI = round(roisData[4] * spatialScale);
302+
int ystartROI = scaleAndRoundRoi(roisData[2], spatialScale);
303+
int yendROI = scaleAndRoundRoi(roisData[4], spatialScale);
300304
int roiHeight = std::max(yendROI - ystartROI + 1, 1);
301305
roiRatio = (float)roiHeight / height;
302306

303307
ystart = ystartROI + y0 * roiRatio;
304308
yend = ystartROI + std::ceil((y0 + 1) * roiRatio);
305309

306-
xstartROI = round(roisData[1] * spatialScale);
307-
int xendROI = round(roisData[3] * spatialScale);
310+
xstartROI = scaleAndRoundRoi(roisData[1], spatialScale);
311+
int xendROI = scaleAndRoundRoi(roisData[3], spatialScale);
308312
int roiWidth = std::max(xendROI - xstartROI + 1, 1);
309313
roiRatio = (float)roiWidth / width;
310314

0 commit comments

Comments
 (0)