Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private string Ocr(Bitmap image_s, bool isFull, bool isNum = false)
- {
- string temp = "";
- Image<Gray,byte> src = new Image<Gray,byte>(image_s);
- double ratio = 1;
- while (true)
- {
- ratio = (double)CvInvoke.cvCountNonZero(src) / (src.Width * src.Height);
- if (ratio > 0.5) break;
- src = src.Dilate(2);
- }
- Bitmap image = src.ToBitmap();
- TesseractProcessor ocr;
- if (isFull)
- ocr = full_tesseract;
- else if (isNum)
- ocr = num_tesseract;
- else
- ocr = ch_tesseract;
- int cou = 0;
- ocr.Clear();
- ocr.ClearAdaptiveClassifier();
- temp = ocr.Apply(image);
- while (temp.Length > 3)
- {
- Image<Gray, byte> temp2 = new Image<Gray, byte>(image);
- temp2 = temp2.Erode(2);
- image = temp2.ToBitmap();
- ocr.Clear();
- ocr.ClearAdaptiveClassifier();
- temp = ocr.Apply(image);
- cou++;
- if (cou > 10)
- {
- temp = "";
- break;
- }
- }
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement