- Hi, I'm Cameron McKenzie
@cameronmcnz on Twitter.
And I wanted to talk to you about
Optical Character Resolution of Images with UiPath.
That is somebody giving you an image.
There's a bunch of texts on it that you need.
How do you get it off there?
So here's the image invoice that I wanna process.
Now I wanna get the invoice number,
the invoice date, and then the total down here.
And this is a JPEG image.
You can see it's a dot JPG
and it's this file right here.
And it's being viewed inside of a photo viewer.
And so I gonna have to do optical character recognition
to extract that data on it.
And so I gonna kick that off
by creating a new process project,
and I'll call it JPEG invoice OCR,
'cause we're processing an invoice here.
That is a JPEG.
And the first thing I do when I start this off is
I use the start power shell command utility.
I'm gonna click open main window first,
but yeah, I try to just use the regular run process
and it didn't work.
So I have to use this activity here,
which says re invoke the power shell command.
And here you just put the name of the JPEG file.
It's in this folder,
invoice images, the invoices is C23OO3.
So that kicks things off.
And the other thing I like to do is
I like to just maximize the file as well.
So when I'm doing OCR,
I like every file to be maximized on the page,
that makes things go a little bit smoother.
So that means sending a hotkey to the page
and the hotkey to maximize, It's just Alt+Space+X
And believe it or not,
sometimes it doesn't work on the first try.
So I always put two in,
I just think it's a weird thing that happened.
I think maybe it's actually Alt+Space and then X,
I think what happens is the space and the X
happen too quickly together.
And sometimes the X isn't registered.
So there you go.
I always like to put that in twice.
It doesn't have anything to do with OCR
just has to do with the way I like processing the files.
Anyways, the thing you're probably interested in is the OCR.
So let's just say, I wanna get the invoice number,
the invoice date, and the total for the invoice,
and maybe write that out to database or Excel
at some point in time in the future.
In order to do that, I'll need three variables.
And so I gonna create one variable
in the sequence called invoice number,
another variable called invoice date
and a final one called invoice total.
And they're all of type string
and they're all have scope inside the sequence.
And then what I do is I look for my OCR activity
and specifically the get OCR text.
I drag this on,
and it says to me,
"Okay, indicate on the screen, what you're going after."
Right now I think I'm gonna go after.
Well, what's the first thing that shows up
the first thing that shows up is the invoice number.
And so I'm gonna specify here in OCR,
under the output text I'm gonna say this.
Well, initialize the invoice number.
I have to click on screen.
And by the way, when I do this,
I'm just gonna write this here.
I have to click on F3
in order to select a piece of the PDF file.
So I can't really show you that on a screencast,
but I wanna tell you that
it's gonna happen in just a second.
But here we go i wanna indicate where
I wanna extract text from that PDF file.
So I'll click indicate on screen,
click Alt+Tab to get to the invoice
and then click F3.
And after clicking F3, I can highlight that invoice number.
As I come back to UiPath,
you can see that it's been selected here.
And so hopefully it'll be able to extract
that data from this JPEG.
Now you gonna to do exactly the same thing twice.
So I'm gonna copy this.
Well, I'm gonna do it three times, two more times.
And on this one, we got the invoice number,
on the second one I'll go after the invoice date,
and on the third one, we will go after the invoice total.
And we'll do that again by selecting...
Well, we can't leave it there on the invoice number.
I've gotta click here,
say indicate on screen,
Tab over to the invoice.
And this is gonna be the invoice date.
Again, I can't select individual things on this page
'cause it's an image,
but if I hit function F3,
it does allow me to crop pieces of the page there.
Now that will represent the date.
And then finally, this will be the invoice total.
So again, indicate on screen,
click Function F3,
and then highlight
in this case, it's gonna be the total.
And now I've got all of my OCR working.
When this is done the last thing to do
is just write that information out,
and I can do that with a very simple...
Well, this is the command that I'm gonna put in there.
Invoice number plus invoice date plus invoice total,
(typing)
plus invoice date,
plus invoice total.
And that should give me an idea of exactly
what's happening when the OCR works.
So hopefully we'll get the correct data.
Okay.
So let's save this.
Click save.
And then finally we will do a run.
The page comes up a little bit of OCR happens.
It's all done maximized.
And then we come back to the page
and you can see it's pulled out the invoice number, C3C003.
It's pulled out the date, 03-03-2020.
It looks like it's used an M dash there
instead of a small dash,
but that's something that any data cleansing routine
can handle.
You should always run one of those after OCR,
just to tighten things up a little bit,
and switching an M dash to a normal dash,
shouldn't be too onerous for a software developer.
And then finally 230,
which maps to the total on the invoice.
So yeah, if we take a look at this here.
Yeah, there's C3CO30, that was the invoice number.
03-03-2020 was the date.
And 230 was the total for the invoice.
And all of that was scraped from a JPEG image,
all using OCR.
And there you go.
That's how easy it is to do
Optical Character Resolution of Images with UiPath.
Now, if you enjoyed this tutorial,
head over to The serverside.com,
I got lots of great tutorials on all sorts of things
to do with enterprise software development.
If you're interested in my personal antics,
you can follow me on Twitter @cameronmcnz
and subscribe on YouTube.