VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > C#教程 >
  • csharp: use custom fonts in Emgu.CV

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// from https://stackoverflow.com/questions/35381238/how-to-use-custom-fonts-in-emgucv
string text = "涂聚文(Geovin Du)";
// 下面定义一个矩形区域
int rectWidth = text.Length * (fontSize + 10);
int rectHeight = fontSize + 10;
 
 
//Draw detected area
foreach (Rectangle face1 in faces)
{
    // 声明矩形域
   // Rectangle textArea = new Rectangle(face1.X + face1.Width, face1.Y, rectWidth, rectHeight);
    //grapPic.DrawString(text, font, whiteBrush, textArea);
    //image.Draw(textArea, new Bgr(Color.Red), 2);
    image.Draw(face1, new Bgr(Color.Red), 2); //
 
 
    //中文乱码
    CvInvoke.PutText(image, "geovindu"new System.Drawing.Point(face1.X-25, face1.Y-25), Emgu.CV.CvEnum.FontFace.HersheyScriptComplex,2, new MCvScalar(255, 255, 0), 2);
    System.Drawing.Bitmap bmp;
    bmp = new System.Drawing.Bitmap(200, 45);
    Graphics g = Graphics.FromImage(bmp);
    Font drawFont = new Font("宋体", 24, FontStyle.Bold);
    g.DrawString(text, drawFont, Brushes.Red, new PointF(0, 0));
    g.Save();
    for (int i = 0; i < 200; i++)
    {
        for (int j = 0; j < 45; j++)
        {
            Color c = bmp.GetPixel(i, j);
            if (c.R > 0 || c.B > 0 || c.G > 0)
            {
                CvInvoke.cvSet2D(image, j + 10 + 200, i + 200, new MCvScalar(c.B, c.G, c.R)); //修改对应像素值
            }
        }
    }
    //自定义字体 Geovin Du
    // 'PrivateFontCollection' is in the 'System.Drawing.Text' namespace
    var foo = new PrivateFontCollection();
    //
    string fonfile =Environment.CurrentDirectory+ @"/font/迷你繁篆书.ttf";
    foo.AddFontFile(fonfile);
    var myCustomFont = new Font((FontFamily)foo.Families[0], 36f);
    //Emgu.CV.CvEnum.FontFace.HersheyScriptComplex
    System.Drawing.Bitmap bmpd;
    bmpd = new System.Drawing.Bitmap(200, 45);
    Graphics gg = Graphics.FromImage(bmpd);
    gg.DrawString("涂聚文 Geovin Du", myCustomFont, Brushes.Red, new PointF(0, 0));
    gg.Save();
    //根据图片的大小
    for (int i = 0; i < 200; i++)
    {
        for (int j = 0; j < 45; j++)
        {
            Color c = bmpd.GetPixel(i, j);
            if (c.R > 0 || c.B > 0 || c.G > 0)
            {
                CvInvoke.cvSet2D(image, j + 10 + 500, i +500, new MCvScalar(c.B, c.G, c.R)); //修改对应像素值
            }
        }
    }
 
 
 
}
foreach (Rectangle eye1 in eyes)
{
    image.Draw(eye1, new Bgr(Color.Blue), 2);
}

文章出处:https://www.cnblogs.com/geovindu/p/13291682.html

相关教程