private void browseBtn_Click(object sender, EventArgs e) { openSppFileDialog.ShowDialog(this); pathTextBox.Text = openSppFileDialog.FileName; scanPictureBox.ImageLocation = openSppFileDialog.FileName; using (var engine = new TesseractEngine("./tessdata", "ind", EngineMode.Default)) { Image original_img = new Bitmap(openSppFileDialog.FileName); Point crop_point = new Point(300, 0); Size crop_size = new Size(original_img.Width - 300, original_img.Height); Rectangle crop_area = new Rectangle(crop_point, crop_size); Image cropped_img = cropImage(original_img, crop_area); cropped_img.Save("./cropped_img.png", System.Drawing.Imaging.ImageFormat.Png); using (var img = Pix.LoadFromFile("./cropped_img.png")) { using (Page page = engine.Process(img)) { string spp_str = page.GetText(); int parse_state = 0; // 0,2,4,6,8,10,12,14,16=none, 1=nama, 3=alamat, 5=nmrpolisi, 7=nmrshipment, 9=tujuan, // 11=pemesanan, 13=denstemp, 15=pembeli, 17=produk var i = 0; SppForm spp = new SppForm(); Console.WriteLine(spp_str); for (i = 0; i < spp_str.Length; i++) { if (spp_str[i] == ':') { parse_state++; } else { if (parse_state == 1) { // name spp.Name = spp.Name + spp_str[i]; } else if (parse_state == 2) { spp.Address = spp.Address + spp_str[i]; } else if (parse_state == 3) {// nmrpolisi spp.Police = spp.Police + spp_str[i]; } else if (parse_state == 4) {// nmrshipment spp.Shipment = spp.Shipment + spp_str[i]; } else if (parse_state == 6) {// pemesanan spp.Volume = spp.Volume + spp_str[i]; } else if (parse_state == 7) {// denstemp spp.Quality = spp.Quality + spp_str[i]; } else if (parse_state == 8) {// pembeli spp.Buyer = spp.Buyer + spp_str[i]; } else if (parse_state == 9) {// produk spp.Product = spp.Product + spp_str[i]; } } } setSppTextBox(false); sppNameTextbox.Text = spp.Name; sppAddressTextbox.Text = spp.Address; sppPoliceTextbox.Text = spp.Police; sppShipmentTextbox.Text = spp.Shipment; sppVolumeTextbox.Text = spp.Volume; sppQualityTextbox.Text = spp.Quality; sppBuyerTextbox.Text = spp.Buyer; sppProductTextbox.Text = spp.Product; } } } }
private void browseBtn_Click(object sender, EventArgs e) { openSppFileDialog.ShowDialog(this); pathTextBox.Text = openSppFileDialog.FileName; scanPictureBox.ImageLocation = openSppFileDialog.FileName; using (var engine = new TesseractEngine("./tessdata", "ind", EngineMode.Default)) { Image original_img = new Bitmap(openSppFileDialog.FileName); Point crop_point = new Point(300,0); Size crop_size = new Size(original_img.Width - 300, original_img.Height); Rectangle crop_area = new Rectangle(crop_point, crop_size); Image cropped_img = cropImage(original_img, crop_area); cropped_img.Save("./cropped_img.png", System.Drawing.Imaging.ImageFormat.Png); using (var img = Pix.LoadFromFile("./cropped_img.png")) { using (Page page = engine.Process(img)) { string spp_str = page.GetText(); int parse_state = 0; // 0,2,4,6,8,10,12,14,16=none, 1=nama, 3=alamat, 5=nmrpolisi, 7=nmrshipment, 9=tujuan, // 11=pemesanan, 13=denstemp, 15=pembeli, 17=produk var i = 0; SppForm spp = new SppForm(); Console.WriteLine(spp_str); for(i=0; i<spp_str.Length; i++) { if (spp_str[i] == ':') { parse_state++; } else { if (parse_state == 1) { // name spp.Name = spp.Name + spp_str[i]; } else if (parse_state == 2) { spp.Address = spp.Address + spp_str[i]; } else if (parse_state == 3) {// nmrpolisi spp.Police = spp.Police + spp_str[i]; } else if (parse_state == 4) {// nmrshipment spp.Shipment = spp.Shipment + spp_str[i]; } else if (parse_state == 6) {// pemesanan spp.Volume = spp.Volume + spp_str[i]; } else if (parse_state == 7) {// denstemp spp.Quality = spp.Quality + spp_str[i]; } else if (parse_state == 8) {// pembeli spp.Buyer = spp.Buyer + spp_str[i]; } else if (parse_state == 9) {// produk spp.Product = spp.Product + spp_str[i]; } } } setSppTextBox(false); sppNameTextbox.Text = spp.Name; sppAddressTextbox.Text = spp.Address; sppPoliceTextbox.Text = spp.Police; sppShipmentTextbox.Text = spp.Shipment; sppVolumeTextbox.Text = spp.Volume; sppQualityTextbox.Text = spp.Quality; sppBuyerTextbox.Text = spp.Buyer; sppProductTextbox.Text = spp.Product; } } } }