我在matlab中创建了一个面部检测器,并将其转换为C#代码,然后一切都变得顺利了。我主要使用

 System.Drawing.Bitmap b = new
        System.Drawing.Bitmap("C:*Location of file on computer*");


为了初步获得图像,在最后的步骤中,我有此代码

public static void ratio(System.Drawing.Bitmap b, Dictionary<int, List<int>> map)
    {
        double height=0;
        double width=0;


        foreach (KeyValuePair<int, List<int>> place in map)
        {
            height = place.Value[2] - place.Value[3];
            width = place.Value[0] - place.Value[1];

            if( ((height/width) >= 1) && ((height/width) <=  2 ) )
                draw(b, place, map);
        }
    }

    public static void draw(System.Drawing.Bitmap bmp, KeyValuePair<int, List<int>> place, Dictionary<int, List<int>> map)
    {
        // Create pen.
        Pen blackPen = new Pen(Color.Black, 3);
        // Create coordinates of points that define line.

        int x1 = place.Value[1];   //topleft to topright
        int y1 = place.Value[3];
        int x2 = place.Value[0];
        int y2 = place.Value[3];

        int x3 = place.Value[0];   //topright to bottomright
        int y3 = place.Value[3];
        int x4 = place.Value[0];
        int y4 = place.Value[2];

        int x5 = place.Value[0];   //bottomright to bottomleft
        int y5 = place.Value[2];
        int x6 = place.Value[1];
        int y6 = place.Value[2];

        int x7 = place.Value[1];   //bottomleft to topleft
        int y7 = place.Value[2];
        int x8 = place.Value[1];
        int y8 = place.Value[3];

        // Draw line to screen.
        using (var graphics = Graphics.FromImage(bmp))
        {
            graphics.DrawLine(blackPen, x1, y1, x2, y2);
        }

        using (var graphics = Graphics.FromImage(bmp))
        {
            graphics.DrawLine(blackPen, x3, y3, x4, y4);
        }

        using (var graphics = Graphics.FromImage(bmp))
        {
            graphics.DrawLine(blackPen, x5, y5, x6, y6);
        }

        using (var graphics = Graphics.FromImage(bmp))
        {
            graphics.DrawLine(blackPen, x7, y7, x8, y8);
        }

    }


在脸上画一个盒子。 Ratio使用从连接的组件标签中获得的标签边界来找到人脸的正确比例(我的数字刚刚组成)map是字典,其中包含标签编号以及xmax,xmin,ymax和ymin作为值。一切都可以编译,没有错误,但是,我现在要做的是在脸上画有绘制框的情况下显示所说的图像,我不确定该怎么做

最佳答案

假设这是Windows.Forms应用程序,您只需将PictureBox控件从工具箱拖放到窗体上,将其Dock属性设置为Fill,并在代码中设置其Image属性:

PictureBox1.Image = b;

关于c# - 在位图上画一条线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17552908/

10-09 15:10