Find text in a image (picturebox) with Tesseract

Grant Fullen
Grant Fullen used Ask the Experts™
on
I have some sample code of using Tesseract-OCR.
Right now the code just opens up a image file and extracts what text it can

I have a picturebox.
I have a textbox and a button
 The OCR Button Load the image from the opendialog in the picturebox and extracts what text it can.

I want to type text  in the text box AND if Tesseract can find it in the image then highlight the text it finds on the image in the picture box .
The ocr button does a pretty good job on extracting what text it can .
I will include a sample image i been working with.
Some sample code would be great .
Thanks for all comments and help.
123.tif
Tesseract-OCR.rar
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer
Fellow 2017
Most Valuable Expert 2018
Commented:
Hi Grant,
As you know, I'm not a C# programmer, but here's a solution in another language, AutoHotkey, that may be helpful. The AutoHotkey language is pretty easy to understand, so I'm sure you can convert it to C#.

I haven't yet figured out how to highlight the text in the picture box, so instead of that, I call Tesseract to create a searchable PDF file, and then call Adobe Reader with the search term, so that when Adobe Reader runs, all the search term hits are highlighted.

The first prompt in the program is a standard Windows Browse-for-File dialog, allowing you to select the image file. The next dialog looks like this:

TesseractSearch dialog
After you enter the search term and click OK, the program calls Tesseract to create the searchable PDF and then calls Adobe Reader to highlight the search term.

Here's the AutoHotkey program:

AdobeReaderEXE:="c:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
TesseractEXE:="c:\Program Files (x86)\Tesseract-OCR\tesseract.exe"

FileSelectFile,InputFile,1,,Select image file,All files (*.*)
SplitPath,InputFile,OutFileName,OutDir,OutExt,OutNameNoExt
OutputPath:=OutDir . "\"
OutputFileNoExt:=OutputPath . OutNameNoExt
OutputFile:=OutputFileNoExt . ".pdf"

Gui,Font,s10 w600 c000000,Arial
Gui,Add,Picture,,%InputFile%
Gui,Add,Text,,`nEnter search term (whole words only`, case insensitive) and press OK
Gui,Add,Edit,w300 vSearchTerm
Gui,Add,Button,Default,OK
Gui,Show
Return

ButtonOK:
Gui,Submit,NoHide
RunWait,%TesseractEXE% "%InputFile%" "%OutputFileNoExt%" pdf,,Hide
If (ErrorLevel!=0)
{
  MsgBox,4112,Tesseract Error,Error Level=%ErrorLevel%
  ExitApp
}
Run,"%AdobeReaderEXE%" /A "search=%SearchTerm%" "%OutputFile%"
GuiClose:
GuiEscape:
ExitApp

Open in new window

If you're not familiar with AutoHotkey, my Experts Exchange article will get you going on it:
AutoHotkey - Getting Started

And here are some other articles with sample code:
How to copy the short link of an ID at Experts Exchange to the clipboard with a single keystroke

How to solve the problem of incorrect System Uptime being reported when a system has been up for a long time (approximately 50 days or more)

How to create an on/off toggle to mute the system audio/sound with a single mouse click or single keystroke

Btw, because Tesseract OCR does not do very well on the sample image, many searches don't work, but C3025 does. Regards, Joe

Author

Commented:
Hey Joe THANKS for the effort with the code.
I am hoping to get some help with a c# solution .
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
You're welcome, Grant. I'm sure some C# experts will be along soon. Regards, Joe
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Author

Commented:
SIDE NOTE TO JOE.
HEy i just found about the free community edition of delphi.
https://www.youtube.com/watch?v=XMj8RlJO-zQ
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Thanks for the heads-up, Grant. I was unaware of that edition. I'll give it a spin. Regards, Joe

Author

Commented:
Any C# experts who may have an ideal ?

Author

Commented:
Thanks for your help
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
You're welcome, Grant, happy to help. Regards, Joe

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial