public void TrimString() { int start = 0; while (gystogram[start].count == 0) { start++; } int finish = gystogram.Count - 1; while (gystogram[finish].count == 0) { finish--; } MyBitmap newMBM = new MyBitmap(new Bitmap(str.width, finish - start)); Console.WriteLine(str.width + "---" + str.height); //for (int y = start; y < finish - start - 1; y++) //{ // for (int x = 0; x < str.width; x++) // { // newMBM.bitmap.SetPixel(x, y - (start), str.bitmap.GetPixel(x, y)); // } //} //str = newMBM; }
public static List <GystMember> DoStringGystogram(MyBitmap bitmap) { List <GystMember> gystogram = new List <GystMember>(); for (int x = 0; x < bitmap.height; x++) { gystogram.Add(new GystMember(x)); for (int y = 0; y < bitmap.width; y++) { if (bitmap.bitmap.GetPixel(y, x).ToArgb() != Color.White.ToArgb()) { gystogram[x].Add(); } } } return(gystogram); }
public static List <GystMember> DoWordGystogram(MyBitmap str) { Bitmap newBm = new Bitmap(str.height, str.width); for (int y = 0; y < str.height; y++) { for (int x = 0; x < str.width; x++) { newBm.SetPixel(y, newBm.Height - x - 1, str.bitmap.GetPixel(x, y)); } } MyBitmap turnedString = new MyBitmap(newBm); str = turnedString; List <GystMember> wordGyst = DoStringGystogram(turnedString); //SavePhotoWithGystogram(wordGyst, newBm, "F:\\Progr\\Csh\\wordCounter\\wordCounter\\bin\\Debug\\img\\" + 12 + ".jpg"); return(wordGyst); }
public int Count(Bitmap image) { MyBitmap text = new MyBitmap(image); text.ConvertBitmapToBlackAndWhite(); text.gystogram = Gystogram.DoStringGystogram(text); Gystogram.SavePhotoWithGystogram(text.gystogram, text.bitmap, "F:\\Progr\\Csh\\wordCounter\\wordCounter\\bin\\Debug\\img\\Text_gystogram.jpg"); text.DivideIntoStrings(); int i = 0; foreach (TextString stroke in text.strings) { stroke.gystogram = Gystogram.DoWordGystogram(stroke.str); stroke.TrimString(); Gystogram.SavePhotoWithGystogram(stroke.gystogram, stroke.str.bitmap, "F:\\Progr\\Csh\\wordCounter\\wordCounter\\bin\\Debug\\img\\" + i + ".jpg"); stroke.DivideWords(); i++; } return(0); }
public void DivideWords() { List <GystMember> spaces = MyBitmap.DoSpaceGystogram(gystogram); foreach (GystMember gm in spaces) { Console.WriteLine(gm.value + "--------" + gm.count); } Console.WriteLine("____________________________________"); //int startInd = spaces[0].value; //spaces.RemoveAt(0); //spaces.RemoveAt(0); //int space = FindMaxSpace(spaces); //int y = startInd; //while (y < gystogram.Count) //{ // if (gystogram[y].count != 0) // { // int i = 0; // while (i + y < gystogram.Count && gystogram[y + i].count != 0 || y + i - 1 + space < gystogram.Count && gystogram[y + i - 1 + space].count != 0) // i++; // Bitmap strBitm = new Bitmap(str.width, i); // for (int coordY = 0; coordY < i; coordY++) // { // for (int coordX = 0; coordX < str.width; coordX++) // { // strBitm.SetPixel(coordX, coordY, str.bitmap.GetPixel(coordX, coordY + y - 2)); // } // } // words.Add(new Word(new MyBitmap(strBitm))); // y += i + space; // } // else // { // y++; // } //} }
public Word(MyBitmap word) { this.word = word; }
public TextString(Bitmap str) { this.str = new MyBitmap(str); }