Example #1
0
        // copy from src/layer/proposal.cpp
        private static Mat GenerateAnchors(int baseSize, Mat ratios, Mat scales)
        {
            var numRatio = ratios.W;
            var numScale = scales.W;

            var anchors = new Mat();

            anchors.Create(4, numRatio * numScale);

            var cx = baseSize * 0.5f;
            var cy = baseSize * 0.5f;

            for (var i = 0; i < numRatio; i++)
            {
                var ar = ratios[i];

                var rW = (int)Math.Round(baseSize / Math.Sqrt(ar));
                var rH = (int)Math.Round(rW * ar); //round(baseSize * sqrt(ar));

                for (var j = 0; j < numScale; j++)
                {
                    var scale = scales[j];

                    var rsW = rW * scale;
                    var rsH = rH * scale;

                    var anchor = anchors.Row(i * numScale + j);

                    anchor[0] = cx - rsW * 0.5f;
                    anchor[1] = cy - rsH * 0.5f;
                    anchor[2] = cx + rsW * 0.5f;
                    anchor[3] = cy + rsH * 0.5f;
                }
            }

            return(anchors);
        }