使用图像c#的像素数据绘制边界框

时间:2017-01-15 16:45:00

标签: c# c#-4.0 histogram image-segmentation text-segmentation

我正在尝试使用像素数据绘制边界框。我想生成一个像附加图像中的边界框。我试图绘制折线图并找到每个角色的框坐标。

我对实施感到困惑。任何人都可以指导我吗?

enter image description here

我的代码如下

private void button1_Click(object sender, EventArgs e)
{
    Bitmap bmp = new Bitmap(filename);
    GetBitmap(bmp);
    bmp.Save(@"C:\Users\harinath\Desktop\New folder (2)\hello.jpg");
    List<System.Drawing.Point> bl = new List<System.Drawing.Point>();
    List<System.Drawing.Point> wt = new List<System.Drawing.Point>();
    List<System.Drawing.Point> bt = new List<System.Drawing.Point>();

    int whiteColor = 0;
    int blackColor = 0;

    for (int x = 0; x < bmp.Width; x++)
    {
        for (int y = 0; y < bmp.Height; y++)
        {
            Color color = bmp.GetPixel(x, y);

            if (color.ToArgb() == Color.White.ToArgb())
            {
                wt.Add(new System.Drawing.Point(x, y));
                bt.Add(new System.Drawing.Point(x, 0));
            }
            else if (color.ToArgb() == Color.Black.ToArgb())
            {
                bl.Add(new System.Drawing.Point(x, y));
                bt.Add(new System.Drawing.Point(x, y));
            } 
        }
    }

    //int count = bt.Count;
    //// Point ab = new Point();

    //List<int> xlist = new List<int>();
    //List<int> ylist = new List<int>();
    //for (int i = 0; i < count; i++)
    //{
    //    var a=bt[i].X;
    //    var b =bt[i].Y;
    //    if (b > 0) {     }
    //}

    var series = new Series("test");
    chart1.ChartAreas[0].AxisX.Maximum = bmp.Width;
    chart1.ChartAreas[0].AxisX.Minimum = 0;
    chart1.ChartAreas[0].AxisY.Maximum = bmp.Height;
    chart1.ChartAreas[0].AxisY.Minimum = 0;
    chart1.ChartAreas[0].AxisX.Interval = 5;
    chart1.ChartAreas[0].AxisY.Interval = 2;
    foreach (System.Drawing.Point ls in bt)
    {
        series.Points.AddXY(ls.X, ls.Y);

        series.ChartType = SeriesChartType.Line;
    }

    chart1.Series.Add(series);
    chart1.SaveImage(@"C:\Users\harinath\Desktop\New folder (2)\chart1.png", ChartImageFormat.Png);      

    //textBox1.Text = whiteColor.ToString();
    //textBox2.Text = blackColor.ToString();

    bmp.Save(@"C:\Users\harinath\Desktop\New folder (2)\hello.jpg");
}

0 个答案:

没有答案