none
Image processing in C# RRS feed

  • Question

  • Hi all,

    just wondering does .Net have any libraries that process the image files (.jpg or .png etc).

    To be more precise, let's say i have scanned and uploaded a driver license, and once uploaded, the application should be able to retrieve those information, such as driver licence number, name, date or birth, expiry date etc.

    I was googling, but couldn't see the similar post there, all it has was manipulate the image pixels etc.

    Any suggestions would be greatly appreciated, many thanks. 

    Monday, June 24, 2019 5:41 AM

Answers

  • Greetings Andie.

    Try googling "optical character recognition c#".

    Here's an example.

    https://code.msdn.microsoft.com/windowsapps/NET-OCR-Library-API-for-46f2f312

    • Marked as answer by AndieDu Tuesday, June 25, 2019 6:52 AM
    Tuesday, June 25, 2019 12:18 AM
  • thanks Ante, issue got resolved. 

    To make the opr functional, below are the steps:

    1.Download C# Iron OCR Library from this link: IronOCR Library Download and plz beaware the licencing terms and conditions, and I am not responsible for any licencing breaching etc.

    2. Add IronOcr dll reference to your project.

    3. Add below code:

    private void btnBrowse_Click(object sender, EventArgs e)
    {
    	using (var fbd = new OpenFileDialog())
    	{
    		DialogResult result = fbd.ShowDialog();
    		if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.FileName))
    		{
    			lblFilePath.Text = fbd.FileName;
    		}
    	}
    }
    		
    private void btnScanFile_Click(object sender, EventArgs e)
    {
    	try
    	{
    		rtbText.Text = string.Empty;
    		string textFromImage = clsReadImage.ScreenshotOCR(lblFilePath.Text);
    		if (!string.IsNullOrEmpty(textFromImage))
    			rtbText.Text = textFromImage;
    		else
    			rtbText.Text = "Nothing to add";
    	}
    	catch (Exception ex)
    	{
    		MessageBox.Show(ex.Message);
    	}
    }
    
    static class clsReadImage
    {
    	public static string ScreenshotOCR(string imgFilePath)
    	{
    		string textFromImage = string.Empty;
    		// AutoOcr automatically detects input image properties and makes
    		// an educated best guess at the optimal OCR settings.
    		AutoOcr Ocr = new AutoOcr() { ReadBarCodes = false };
    		var Results = Ocr.Read(imgFilePath);
    	
    		textFromImage = Results.Text;
    		return textFromImage;
    	}
    }

    • Edited by AndieDu Wednesday, June 26, 2019 1:02 AM
    • Marked as answer by AndieDu Wednesday, June 26, 2019 1:03 AM
    Tuesday, June 25, 2019 6:53 AM

All replies

  • anyone?

    sounds like this is a pretty awkward question and no one had come across this before?

    Monday, June 24, 2019 11:39 PM
  • Greetings Andie.

    Try googling "optical character recognition c#".

    Here's an example.

    https://code.msdn.microsoft.com/windowsapps/NET-OCR-Library-API-for-46f2f312

    • Marked as answer by AndieDu Tuesday, June 25, 2019 6:52 AM
    Tuesday, June 25, 2019 12:18 AM
  • great, thanks a lot Ante.
    Tuesday, June 25, 2019 12:46 AM
  • Hi AndieDu,

    >>great, thanks a lot Ante.

    I want to confirm if your question has been solved, If so, please post "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue. If not, please feel free to let us know.

    Best Regads,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, June 25, 2019 1:49 AM
    Moderator
  • will do mate.

    adopting other ones code always involves flip around, and once i made that full functioning, then i will mark it as resolved.

    Tuesday, June 25, 2019 2:20 AM
  • thanks Ante, issue got resolved. 

    To make the opr functional, below are the steps:

    1.Download C# Iron OCR Library from this link: IronOCR Library Download and plz beaware the licencing terms and conditions, and I am not responsible for any licencing breaching etc.

    2. Add IronOcr dll reference to your project.

    3. Add below code:

    private void btnBrowse_Click(object sender, EventArgs e)
    {
    	using (var fbd = new OpenFileDialog())
    	{
    		DialogResult result = fbd.ShowDialog();
    		if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.FileName))
    		{
    			lblFilePath.Text = fbd.FileName;
    		}
    	}
    }
    		
    private void btnScanFile_Click(object sender, EventArgs e)
    {
    	try
    	{
    		rtbText.Text = string.Empty;
    		string textFromImage = clsReadImage.ScreenshotOCR(lblFilePath.Text);
    		if (!string.IsNullOrEmpty(textFromImage))
    			rtbText.Text = textFromImage;
    		else
    			rtbText.Text = "Nothing to add";
    	}
    	catch (Exception ex)
    	{
    		MessageBox.Show(ex.Message);
    	}
    }
    
    static class clsReadImage
    {
    	public static string ScreenshotOCR(string imgFilePath)
    	{
    		string textFromImage = string.Empty;
    		// AutoOcr automatically detects input image properties and makes
    		// an educated best guess at the optimal OCR settings.
    		AutoOcr Ocr = new AutoOcr() { ReadBarCodes = false };
    		var Results = Ocr.Read(imgFilePath);
    	
    		textFromImage = Results.Text;
    		return textFromImage;
    	}
    }

    • Edited by AndieDu Wednesday, June 26, 2019 1:02 AM
    • Marked as answer by AndieDu Wednesday, June 26, 2019 1:03 AM
    Tuesday, June 25, 2019 6:53 AM