如何使用opencvsharp 3折线/ fillpoly库函数

时间:2016-03-13 11:28:31

标签: opencv3.0 opencvsharp

我是openCvSharp的新手,我正在从vs nuget插件学习OpenCvSharp 3。 我能够绘制线条和圆圈。但是我遇到了麻烦 绘制折线/ fillPoly函数。其中一个调用参数是忧虑类型。我认为这是rook_point数组。我尝试了其他版本(定义)来传递数组无效。

我是树桩。如果你能帮忙......请回复。

谢谢, 景


    using OpenCvSharp;
    class Program 
    {
        static void Main()
        {
            // Create black empty images
            Mat src = Mat.Zeros(400, 400, MatType.CV_8UC3);

            int w = 400;
            /* Create some points */
            Point[] rook_points = new Point[20];

            rook_points[0] = new Point(w / 4.0, 7 * w / 8.0);
            rook_points[1] = new Point(3 * w / 4.0, 7 * w / 8.0);
            rook_points[2] = new Point(3 * w / 4.0, 13 * w / 16.0);
            rook_points[3] = new Point(11 * w / 16.0, 13 * w / 16.0);
            rook_points[4] = new Point(19 * w / 32.0, 3 * w / 8.0);
            rook_points[5] = new Point(3 * w / 4.0, 3 * w / 8.0);
            rook_points[6] = new Point(3 * w / 4.0, w / 8.0);
            rook_points[7] = new Point(26 * w / 40.0, w / 8.0);
            rook_points[8] = new Point(26 * w / 40.0, w / 4.0);
            rook_points[9] = new Point(22 * w / 40.0, w / 4.0);
            rook_points[10] = new Point(22 * w / 40.0, w / 8.0);
            rook_points[11] = new Point(18 * w / 40.0, w / 8.0);
            rook_points[12] = new Point(18 * w / 40.0, w / 4.0);
            rook_points[13] = new Point(14 * w / 40.0, w / 4.0);
            rook_points[14] = new Point(14 * w / 40.0, w / 8.0);
            rook_points[15] = new Point(w / 4.0, w / 8.0);
            rook_points[16] = new Point(w / 4.0, 3 * w / 8.0);
            rook_points[17] = new Point(13 * w / 32.0, 3 * w / 8.0);
            rook_points[18] = new Point(5 * w / 16.0, 13 * w / 16.0);
            rook_points[19] = new Point(w / 4.0, 13 * w / 16.0);

            Cv2.FillPoly(src, rook_points, true, new Scalar(255, 255, 55));  // invalid parameter

            using (new Window("Image", src))
                Cv2.WaitKey(0);
        }
    }

1 个答案:

答案 0 :(得分:0)

如果您查看下面关于FillPoly和Polylines链接的帖子,您将看到需要一个Points列表列表才能调用FillPoly。

https://github.com/shimat/opencvsharp/issues/181

这是一个简单的例子。

// --- Example ----------
var field = [];

field[0] = 'One';
field[1] = 1;
field[3] = true;
field[5] = 43.68;
field[7] = 'theLastElement';
// --- Example ----------

var originalLength;

// Store the length of the array.
originalLength = field.length;

for (var i in field) {
  // Attach the truthy values upon the end of the array. 
  field.push(field[i]);
}

// Delete the original range within the array so that
// only the new elements are preserved.
field.splice(0, originalLength);