In order to use the Vision API, you first need to provision it in Azure. This video demonstrates how to provision the Vision API, get the keys and endpoint, and update the project.
- [Instructor] Let's talk about describing, categorizing, and tagging pictures using the Vision API. Now, if you're catching me directly in this chapter, what you might want to do is go into the provided source code and go into the 01_04 folder, the End project, and go ahead and unzip it. I already did that and I can show you that I went ahead and renamed it to visionproject and I made sure that I ran NPM install. You should have a folder called node_modules created in there after you run NPM install.
Then I open the project in VS Code and this is where in the source folder, index.ts and config.ts, where we'll be writing bulk of our code. Now, before you can use any part of the Vision API, you'll need to provision its use for yourself. And the easiest way to do that is go to the Azure portal and go ahead and sign in. Once you have signed in to the Azure portal, go ahead and click on this New button up here.
And search for the word Vision. And you should see a choice pop open called Computer Vision API. Go ahead and click on that. So as it tells you that you can use the Computer Vision API to generate tags, read printed text, handwritten text, celebrities and landmarks, et cetera. So this is what we'll be using. So I'm going to go ahead and click this Create button. Let's give it a name. I'm going to call it MyVisionAPI.
I'm going to target the West U.S. data center. Now, the reason I'm targeting the West U.S. data center is because Vision API, it's in its very early phases right now. Or rather, not just the Vision API, but a bunch of other APIs that I'll also be showing you. And not all of these work in all data centers at the moment. I do expect that in the very near future, everything will work in every single data center. But West U.S. is one of those data centers where everything works.
So let's go ahead and pick that. So I'm going to pick a pricing tier and I'll just stick with the free tier. That's good enough for development. But the good news is that when you're ready to roll this into production, you can change this to a paid version and then basically scale up your service. You'll also need to create a resource group. I already have one, so I'll go ahead and pick an existing resource group. Go ahead and click the Create button. Now, once this resource is created, click on the All Resources link on the left.
Look for MyVisionAPI that you just created and go to the Overview button. This link here, this endpoint, we're going to need that. So go ahead and copy it. And I'm going to place this in my config.ts file. Now, in this config.ts file, I will be adding a number of keys and endpoints for different kinds of services that I will use. So let me go ahead and create a node for vision and this shall be an object and its endpoint, as you can see, that we just copied over, is this.
We will also need keys. So let's go over here and click on this Show Access Keys link. Now, your keys are going to be different from mine. Please don't use my keys, because then you'll be targeting my Azure AD subscription. Not to mention that my keys won't work anywhere, because I'm going to delete this Vision API resource before the course ships. So make sure that you use your access keys, not mine. My keys won't work for you.
So let's go ahead and click the copy button here. So let's go ahead and place key one in quotes over here. And key two. Let's go ahead and grab that as well. And let's place that over here. Now, what's the difference between these two keys? Actually, there is no difference. These two keys are identical. The reason they have given you two is just as a backup. Let's say one key gets compromised and you need to regenerate the keys, you now have the ability to regenerate a key while the other key makes sure that your application continues to work.
That's basically it. There is really no other reason for having these two keys. They're identical in every regard. Great, my project is now set up. Now, we'll dive into index.ts and write some interesting code targeting the Vision API.
- Setting up the project
- Writing code to describe an image
- Returning multiple descriptions
- Writing an analyze method
- Applying tags and categories
- Analyzing colors
- Identifying art and adult content
- Recognizing celebrities and landmarks
- Handwriting and OCR
- Detecting faces and emotions
- Identifying people