Skip to content

Commit 8a5dc78

Browse files
committed
Initial commit
1 parent a360b6a commit 8a5dc78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5189
-0
lines changed

ImageRecognition/CharacterInfo.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace ImageRecognition
2+
{
3+
public sealed class CharacterInfo
4+
{
5+
internal PxColor m_color;
6+
7+
internal PxColor m_bgColor;
8+
9+
internal bool[,] m_pixelCoordinate;
10+
11+
internal FontWeight m_fontWeight;
12+
13+
public short BottomYCor{get;set;}
14+
15+
public char Character{get;set;}
16+
17+
public Direction CharacterDirection{get;set;}
18+
19+
public byte Height{get;set;}
20+
21+
public short LeftXCor{get;set;}
22+
23+
public short RightXCor{get;set;}
24+
25+
public short TopYCor{get;set;}
26+
27+
public byte Width{get;set;}
28+
29+
public CharacterInfo()
30+
{
31+
}
32+
}
33+
}

ImageRecognition/CharacterPixel.cs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
5+
using System.Xml.Linq;
6+
7+
namespace ImageRecognition
8+
{
9+
class CharacterPixel
10+
{
11+
private const string dataSource = "PixelFormat.xml";
12+
13+
private readonly XDocument XmlDoc;
14+
15+
private readonly string FullDbPath = string.Empty;
16+
17+
internal List<CharacterInfo> m_characterInfo = new List<CharacterInfo>();
18+
19+
internal CharacterPixel()
20+
{
21+
this.FullDbPath = Path.GetFullPath("PixelFormat.xml");
22+
this.XmlDoc = XDocument.Load(this.FullDbPath);
23+
this.GenerateChracterPixel();
24+
}
25+
26+
private static bool[,] ChangeOrderVerticalLeftToRight(bool[,] pixInfo)
27+
{
28+
bool[,] flagArray;
29+
if (pixInfo != null)
30+
{
31+
byte length = (byte)pixInfo.GetLength(0);
32+
byte num = (byte)pixInfo.GetLength(1);
33+
bool[,] flagArray1 = new bool[num, length];
34+
for (short i = 0; i < length; i = (short)(i + 1))
35+
{
36+
for (short j = 0; j < num; j = (short)(j + 1))
37+
{
38+
short num1 = (short)(length - i - 1);
39+
flagArray1[j, i] = pixInfo[num1, j];
40+
}
41+
}
42+
flagArray = flagArray1;
43+
}
44+
else
45+
{
46+
flagArray = null;
47+
}
48+
return flagArray;
49+
}
50+
51+
internal List<Dimension> DistinctWidthHeight()
52+
{
53+
List<Dimension> dimensions = new List<Dimension>();
54+
foreach (CharacterInfo mCharacterInfo in this.m_characterInfo)
55+
{
56+
Dimension dimension = new Dimension()
57+
{
58+
m_height = mCharacterInfo.Height,
59+
m_width = mCharacterInfo.Width
60+
};
61+
if (!dimensions.Contains(dimension))
62+
{
63+
Dimension dimension1 = new Dimension()
64+
{
65+
m_height = mCharacterInfo.Height,
66+
m_width = mCharacterInfo.Width
67+
};
68+
dimensions.Add(dimension1);
69+
}
70+
}
71+
return dimensions;
72+
}
73+
74+
private void GenerateChracterPixel()
75+
{
76+
Regex regex = new Regex("(?<xCor>(\\d)+)[,](?<yCor>(\\d)+)");
77+
string[] strArrays = new string[] { "TypeOne", "TypeTwo" };
78+
for (int i = 0; i < (int)strArrays.Length; i++)
79+
{
80+
string str = strArrays[i];
81+
string str1 = str;
82+
var collection =
83+
from subitem in this.XmlDoc.Descendants(str).Elements<XElement>("CharacterInfo")
84+
let xElement = subitem.Element("ParamValue")
85+
where xElement != null
86+
let element = subitem.Element("PixelInfo")
87+
where element != null
88+
select new { Character = char.Parse(xElement.Value), PixelInfo = element.Value, CharacterDirection = Direction.Horizontal, FontWeight = (str1 == "TypeTwo" ? FontWeight.Bold : FontWeight.Normal), Pixel = regex.Matches(element.Value) };
89+
foreach (var variable in collection)
90+
{
91+
List<PixelPoint> list = (
92+
from Match oMatch in variable.Pixel
93+
let xCor = short.Parse(oMatch.Groups["xCor"].Value)
94+
let yCor = short.Parse(oMatch.Groups["yCor"].Value)
95+
select new PixelPoint(xCor, yCor)).ToList<PixelPoint>();
96+
CharacterInfo characterInfo = new CharacterInfo();
97+
if (list.Count > 0)
98+
{
99+
list.Sort((PixelPoint object1, PixelPoint object2) => object1.XCor.CompareTo(object2.XCor));
100+
PixelPoint item = list[list.Count - 1];
101+
short num = item.XCor;
102+
item = list[0];
103+
byte num1 = (byte)(num - item.XCor + 1);
104+
list.Sort((PixelPoint object1, PixelPoint object2) => object1.YCor.CompareTo(object2.YCor));
105+
item = list[list.Count - 1];
106+
short num2 = item.YCor;
107+
item = list[0];
108+
byte num3 = (byte)(num2 - item.YCor + 1);
109+
bool[,] flagArray = new bool[num1, num3];
110+
foreach (PixelPoint pixelPoint in list)
111+
{
112+
flagArray[pixelPoint.XCor, pixelPoint.YCor] = true;
113+
}
114+
characterInfo.Character = variable.Character;
115+
characterInfo.m_fontWeight = variable.FontWeight;
116+
characterInfo.CharacterDirection = variable.CharacterDirection;
117+
characterInfo.m_pixelCoordinate = flagArray;
118+
characterInfo.Width = num1;
119+
characterInfo.Height = num3;
120+
this.m_characterInfo.Add(characterInfo);
121+
CharacterInfo characterInfo1 = new CharacterInfo()
122+
{
123+
Character = variable.Character,
124+
m_fontWeight = variable.FontWeight,
125+
CharacterDirection = Direction.Vertical,
126+
m_pixelCoordinate = CharacterPixel.ChangeOrderVerticalLeftToRight(flagArray),
127+
Width = num3,
128+
Height = num1
129+
};
130+
characterInfo = characterInfo1;
131+
this.m_characterInfo.Add(characterInfo);
132+
}
133+
}
134+
}
135+
}
136+
}
137+
}

0 commit comments

Comments
 (0)