Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the error is coming at the time of continuously read Images after 210 images.
i need to read rapidly more than 2000 images or more
i'm getting error at line of "objModi.Create(getfile);"

What I have tried:

if (filecount > i)
{
file_name = (info1[i]).ToString();
fileID = file_name.Replace(".jpg", "");
getfile = _path + "\\" + file_name;
MovePath = _path + "\\" + file_name;
Bitmap Limg = new Bitmap(getfile);
Bitmap img = Limg.Clone(new System.Drawing.Rectangle(x = 100, y = 630, width = 1440, height = 250), Limg.PixelFormat);
int origWidth = img.Width;
int origHeight = img.Height;
float imgRatio = origWidth / origHeight;
float newWidth = pictureBox1.Width;
float newHeight = newWidth / imgRatio;
Image picimg = new Bitmap(img, Convert.ToInt32(newWidth), Convert.ToInt32(newHeight));
pictureBox1.Image = picimg;
img.Dispose();
Limg.Dispose();
linklbImagename.Text = file_name;

//HALLTICKET NO
x = 310;
if (x == 310)
{
y = 700; width = 300; height = 70;
Bitmap source = new Bitmap(getfile);
Bitmap CroppedImage = source.Clone(new System.Drawing.Rectangle(x, y, width, height), source.PixelFormat);
pictureBox2.Image = new Bitmap(CroppedImage);
imgset = getfile;
source.Dispose();
if (!Directory.Exists(@"D:\OCRREAD\Provisional"))
{
Directory.CreateDirectory(@"D:\OCRREAD\Provisional");
}
CroppedImage.Save(@"D:\OCRREAD\" + file_name);
getfile = @"D:\OCRREAD\" + file_name;
MODI.Document objModi = new MODI.Document();
objModi.Create(getfile);
objModi.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
MODI.Image image = (MODI.Image)objModi.Images[0];
MODI.Layout layout = image.Layout;
string strarray = layout.Text;
HalTicketvalue = layout.Text;
HalTicketvalue = HalTicketvalue.Replace("O", "0").Replace(" ", "").Replace(".", "");
File.Delete(getfile);
objModi.Close();
txtHTNo.Text = HalTicketvalue.Trim();
//System.Runtime.InteropServices.Marshal.FinalReleaseComObject(image);
//System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objModi);
}

//REFERENCE NO
x = 260;
if (x == 260)
{
y = 610; width = 300; height = 80;
Bitmap source = new Bitmap(imgset);
Bitmap CroppedImage = source.Clone(new System.Drawing.Rectangle(x, y, width, height), source.PixelFormat);
pictureBox3.Image = new Bitmap(CroppedImage);
source.Dispose();
CroppedImage.Save(@"D:\OCRREAD\" + file_name);
getfile = @"D:\OCRREAD\" + file_name;
MODI.Document objModi = new MODI.Document();
objModi.Create(getfile);
objModi.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
MODI.Image image = (MODI.Image)objModi.Images[0];
MODI.Layout layout = image.Layout;
ReferenceValue = layout.Text;
File.Delete(getfile);
ReferenceValue = ReferenceValue.Replace(".", "").Replace(":", "").Replace(",", "").Replace("D", "").Replace(")", "").Replace(">", "").Replace("I", "").Replace("o", "").Replace("j", "").Replace("J", "").Replace("x", "").Replace("]", "").Replace("O", "0").Replace("a", "").Replace(";", "").Replace(" ", "").Replace("i", "");
objModi.Close();
txtRefNo.Text = ReferenceValue.Trim();
}

//STATINORY NO
x = 1265;
if (x == 1265)
{
y = 95; width = 260; height = 100;
Bitmap source = new Bitmap(imgset);
Bitmap CroppedImage = source.Clone(new System.Drawing.Rectangle(x, y, width, height), source.PixelFormat);
pictureBox4.Image = new Bitmap(CroppedImage);
source.Dispose();
CroppedImage.Save(@"D:\OCRREAD\" + file_name);
getfile = @"D:\OCRREAD\" + file_name;
MODI.Document objModi = new MODI.Document();
objModi.Create(getfile);
objModi.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
MODI.Image image = (MODI.Image)objModi.Images[0];
MODI.Layout layout = image.Layout;
stationaryValue = layout.Text;
File.Delete(getfile);
objModi.Close();
txtStationary.Text = stationaryValue.Replace(":", "").Replace("O", "0").Trim();
}
Posted
Updated 11-Aug-16 20:58pm

1 solution

That line exists several times in your code snippet... But anyway, it is inside a repeated sequence:
CroppedImage.Save(@"D:\OCRREAD\" + file_name);
getfile = @"D:\OCRREAD\" + file_name;
MODI.Document objModi = new MODI.Document();
objModi.Create(getfile);

Bitmap.Save returns quickly, the operating system may still be writing the file to disk. And during that time, you cannot open the file for reading (which MODI.Document.Create must do).
How to solve that problem? By trying and re-trying after a short Thread.Sleep for a limited number of times.

By the way, you ought to do a lot of refactoring. There is a lot of copy-paste code, and the framework offers better options for some tasks.
E.g. define the path in one place
C#
string OcrReadPath = @"D:\OCRREAD";

use System.IO.Path to handle it and add some more variables:
C#
string getfile = System.IO.Path.Combine(OcrRead, file_name);
CroppedImage.Save(getfile);
and , of course, use better variable names (getfile looks more like an instruction, not like a variable).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900