public string[] DecodeImage(Bitmap bmp) { var decodedSymbolsList = new List<string>(); int objectMaxHeight = 0; int objectMaxWidth = 0; foreach (Standart standart in Standarts) { if (standart.IdealStandart.Height > objectMaxHeight) objectMaxHeight = standart.IdealStandart.Height; if (standart.IdealStandart.Width > objectMaxWidth) objectMaxWidth = standart.IdealStandart.Width; } int rows = bmp.Height/objectMaxHeight; int colls = bmp.Width/objectMaxWidth; for (int i = 0; i < rows; i++) { for (int j = 0; j < colls; j++) { int x = j*objectMaxWidth; int y = i*objectMaxHeight; string symbol; decodedSymbolsList.Add(DecodeSymbol(bmp, x, y, out symbol) ? symbol : "ERR"); } } return decodedSymbolsList.ToArray(); }
private Standart[] InitStandarts() { var standarts = new List<Standart>(Constants.StandartResourseNames.Length); for (int i = 0; i < Constants.StandartResourseNames.Length; i++) { string standartResourseName = Constants.StandartResourseNames[i]; var bmp = (Bitmap) Lab1.Standarts.ResourceManager.GetObject(standartResourseName); Standart standart = InitStandart(bmp); standart.Symbol = Constants.StandartSymbols[i]; standarts.Add(standart); } return standarts.ToArray(); }
private int[] GetSamples(Bitmap bmp, int x, int y) { if (Standarts.Length == 0) return new int[0]; var samples = new List<int>(); unsafe { BitmapData bitmapData = bmp.LockBits( new Rectangle(x, y, Standarts[0].IdealStandart.Width, Standarts[0].IdealStandart.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); int bytesPerPixel = Image.GetPixelFormatSize(bmp.PixelFormat)/8; int heightInPixels = bitmapData.Height; int widthInBytes = bitmapData.Width*bytesPerPixel; var ptrFirstPixel = (byte*) bitmapData.Scan0; for (int row = 0; row < heightInPixels; row++) { int number = 0; byte* currentLine = ptrFirstPixel + (row*bitmapData.Stride); for (int startByte = 0, cell = 0; startByte < widthInBytes; startByte = startByte + bytesPerPixel, cell++) { int blue = currentLine[startByte]; int green = currentLine[startByte + 1]; int red = currentLine[startByte + 2]; if (blue + green + red == 0) { number |= 1 << cell; } } samples.Add(number); } bmp.UnlockBits(bitmapData); } return samples.ToArray(); }
private int[] IncedenceMatrixRowFill(bool[] mask, bool[] idealStandart) { var realises = new List<int>(); int number = 0; for (int i = 0; i < idealStandart.Length; i++) { if (idealStandart[i]) { number |= 1 << i; } } CreateRealises(realises, number, mask, 0); if (realises.Count == 0) realises.Add(number); return realises.ToArray(); }
public static string[] Split(this string str, string[] exps) { List<string> list = new List<string>(); int start_index = 0; int buff = 0; int i = 0; Dictionary<int, int> matches = new Dictionary<int, int>(); while (true) { for (i = 0; i < exps.Length; i++) { buff = str.IndexOf(exps[i], start_index); if (buff != -1) { matches.Add(i, buff); } } if (matches.Count == 0) { list.Add(str.Substring(start_index, str.Length - start_index)); break; } matches = matches.OrderBy(x => x.Value).ToDictionary(x=>x.Key,y=>y.Value); list.Add(str.Substring(start_index, matches.ElementAt(0).Value - start_index)); start_index = matches.ElementAt(0).Value + exps[matches.ElementAt(0).Key].Length; matches.Clear(); } return list.ToArray(); }
public static string[] Split(this string str, string exp) { List<string> list = new List<string>(); int s_index = 0; int end_index = 0; while (true) { s_index = str.IndexOf(exp, s_index); if (s_index == -1) { if (end_index < str.Length) { list.Add(str.Substring(end_index, str.Length - end_index)); } break; } list.Add(str.Substring(end_index, s_index - end_index)); end_index = s_index + exp.Length; s_index++; } return list.ToArray(); }
public static string[] ToStringArray(this CaptureCollection col) { List<string> list = new List<string>(); for (int i = 0; i < col.Count; i++) { if (!list.Contains(col[i].Value)) list.Add(col[i].Value); } return list.ToArray(); }