Esempio n. 1
0
    public static void render_2D(ref OpenCvSharp.Mat left_display, sl.float2 img_scale, ref sl.Objects objects, bool render_mask, bool isTrackingON)
    {
        OpenCvSharp.Mat  overlay    = left_display.Clone();
        OpenCvSharp.Rect roi_render = new OpenCvSharp.Rect(0, 0, left_display.Size().Width, left_display.Size().Height);

        OpenCvSharp.Mat mask = new OpenCvSharp.Mat(left_display.Rows, left_display.Cols, OpenCvSharp.MatType.CV_8UC1);

        int line_thickness = 2;

        for (int i = 0; i < objects.numObject; i++)
        {
            sl.ObjectData obj = objects.objectData[i];
            if (Utils.renderObject(obj, isTrackingON))
            {
                OpenCvSharp.Scalar base_color = Utils.generateColorID_u(obj.id);

                // Display image scale bouding box 2d
                if (obj.boundingBox2D.Length < 4)
                {
                    continue;
                }

                Point top_left_corner     = Utils.cvt(obj.boundingBox2D[0], img_scale);
                Point top_right_corner    = Utils.cvt(obj.boundingBox2D[1], img_scale);
                Point bottom_right_corner = Utils.cvt(obj.boundingBox2D[2], img_scale);
                Point bottom_left_corner  = Utils.cvt(obj.boundingBox2D[3], img_scale);

                // Create of the 2 horizontal lines
                Cv2.Line(left_display, top_left_corner, top_right_corner, base_color, line_thickness);
                Cv2.Line(left_display, bottom_left_corner, bottom_right_corner, base_color, line_thickness);
                // Creation of two vertical lines
                Utils.drawVerticalLine(ref left_display, bottom_left_corner, top_left_corner, base_color, line_thickness);
                Utils.drawVerticalLine(ref left_display, bottom_right_corner, top_right_corner, base_color, line_thickness);

                // Scaled ROI
                OpenCvSharp.Rect roi = new OpenCvSharp.Rect(top_left_corner.X, top_left_corner.Y, (int)top_right_corner.DistanceTo(top_left_corner), (int)bottom_right_corner.DistanceTo(top_right_corner));

                overlay.SubMat(roi).SetTo(base_color);

                sl.float2 position_image = getImagePosition(obj.boundingBox2D, img_scale);
                Cv2.PutText(left_display, obj.label.ToString(), new Point(position_image.x - 20, position_image.y - 12), HersheyFonts.HersheyComplexSmall, 0.5f, new Scalar(255, 255, 255, 255), 1);

                if (!float.IsInfinity(obj.position.Z))
                {
                    string text = Math.Abs(obj.position.Z).ToString("0.##M");
                    Cv2.PutText(left_display, text, new Point(position_image.x - 20, position_image.y), HersheyFonts.HersheyComplexSmall, 0.5, new Scalar(255, 255, 255, 255), 1);
                }
            }
        }

        // Here, overlay is as the left image, but with opaque masks on each detected objects
        Cv2.AddWeighted(left_display, 0.7, overlay, 0.3, 0.0, left_display);
    }
Esempio n. 2
0
    public TrackingViewer(sl.Resolution res, int fps_, float D_max, int duration)
    {
        // ----------- Default configuration -----------------

        // window size
        window_width  = (int)res.width;
        window_height = (int)res.height;

        // Visualization configuration
        camera_offset = 50;

        // history management
        min_length_to_draw = 3;

        // camera settings
        fov = -1.0f;

        // Visualization settings
        background_color     = new Scalar(248, 248, 248, 255);
        has_background_ready = false;
        background           = new OpenCvSharp.Mat(window_height, window_width, MatType.CV_8UC4, background_color);

        Scalar ref_ = new Scalar(255, 117, 44, 255);

        for (int p = 0; p < 3; p++)
        {
            fov_color[p] = (ref_[p] + 2 * background_color[p]) / 3;
        }

        // SMOOTH
        do_smooth = false;

        // Show last 3.0 seconds
        history_duration = (ulong)(duration) * 1000 * 1000 * 1000; //convert sc to ns

        // Smoothing window: 80ms
        smoothing_window_size = (int)(Math.Ceiling(0.08f * fps_) + .5f);

        // invert Z due to Y axis of ocv windows
        z_min = -D_max;
        x_min = z_min / 2.0f;
        x_max = -x_min;

        x_step = (x_max - x_min) / window_width;
        z_step = Math.Abs(z_min) / (window_height - camera_offset);
    }
Esempio n. 3
0
        /// <summary>
        /// N次元行列として初期化
        /// </summary>
        /// <param name="sizes">n-次元配列の形状を表す,整数型の配列.</param>
        /// <param name="type">配列の型.1-4 チャンネルの行列を作成するには MatType.CV_8UC1, ..., CV_64FC4 を,
        /// マルチチャンネルの行列を作成するには,MatType.CV_8UC(n), ..., CV_64FC(n) を利用してください.</param>
        /// <param name="s">各行列要素を初期化するオプション値.初期化の後ですべての行列要素を特定の値にセットするには,
        /// コンストラクタの後で,SetTo(Scalar value) メソッドを利用してください.</param>
#else
        /// <summary>
        /// constructs n-dimensional matrix
        /// </summary>
        /// <param name="sizes">Array of integers specifying an n-dimensional array shape.</param>
        /// <param name="type">Array type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices,
        /// or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.</param>
        /// <param name="s">An optional value to initialize each matrix element with.
        /// To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .</param>
#endif
        protected Mat(IEnumerable <int> sizes, MatType type, Scalar s)
            : base(sizes, type, s)
        {
        }
Esempio n. 4
0
        /// <summary>
        /// 指定したサイズ・型の2次元の行列で、要素をスカラー値で埋めて初期化
        /// </summary>
        /// <param name="size"> 2 次元配列のサイズ: Size(cols, rows) . Size() コンストラクタでは,行数と列数が逆順になっていることに注意してください.</param>
        /// <param name="type">配列の型.1-4 チャンネルの行列を作成するには MatType.CV_8UC1, ..., CV_64FC4 を,
        /// マルチチャンネルの行列を作成するには,MatType.CV_8UC(n), ..., CV_64FC(n) を利用してください.</param>
        /// <param name="s">各行列要素を初期化するオプション値.初期化の後ですべての行列要素を特定の値にセットするには,
        /// コンストラクタの後で,SetTo(Scalar value) メソッドを利用してください.</param>
#else
        /// <summary>
        /// constucts 2D matrix and fills it with the specified Scalar value.
        /// </summary>
        /// <param name="size">2D array size: Size(cols, rows) . In the Size() constructor,
        /// the number of rows and the number of columns go in the reverse order.</param>
        /// <param name="type">Array type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices,
        /// or CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.</param>
        /// <param name="s">An optional value to initialize each matrix element with.
        /// To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .</param>
#endif
        protected Mat(Size size, MatType type, Scalar s)
            : base(size, type, s)
        {
        }
Esempio n. 5
0
        /// <summary>
        /// 指定したサイズ・型の2次元の行列で、要素をスカラー値で埋めて初期化
        /// </summary>
        /// <param name="rows">2次元配列における行数.</param>
        /// <param name="cols">2次元配列における列数.</param>
        /// <param name="type">配列の型.1-4 チャンネルの行列を作成するには MatType.CV_8UC1, ..., CV_64FC4 を,
        /// マルチチャンネルの行列を作成するには,MatType.CV_8UC(n), ..., CV_64FC(n) を利用してください.</param>
        /// <param name="s">各行列要素を初期化するオプション値.初期化の後ですべての行列要素を特定の値にセットするには,
        /// コンストラクタの後で,SetTo(Scalar value) メソッドを利用してください.</param>
#else
        /// <summary>
        /// constucts 2D matrix and fills it with the specified Scalar value.
        /// </summary>
        /// <param name="rows">Number of rows in a 2D array.</param>
        /// <param name="cols">Number of columns in a 2D array.</param>
        /// <param name="type">Array type. Use MatType.CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices,
        /// or MatType. CV_8UC(n), ..., CV_64FC(n) to create multi-channel matrices.</param>
        /// <param name="s">An optional value to initialize each matrix element with.
        /// To set all the matrix elements to the particular value after the construction, use SetTo(Scalar s) method .</param>
#endif
        protected Mat(int rows, int cols, MatType type, Scalar s)
            : base(rows, cols, type, s)
        {
        }
 public static extern IntPtr core_OutputArray_new_byScalar(Scalar val);