# How to Use Nyckel to Reverse-Engineer Google Vision API.
## Introduction
The world we found ourselves in today is developing rapidly with the use of sophisticated technology which makes it much easier for us to achieve a specific task that could have taken ages within a fraction of a second.
Folks that live in the past century might have thought about days like this but do not have enough resources and technology to achieve this incredible goal.
Nowadays, with the aid of Artificial intelligence and Machine Learning, humans can design and build robots that can emulate human behavior perfectly and also think like a human does.
Robots are now being trained on how to perform various tasks which include the identification and detection of images with a twinkle of an eye.
In this article, you will learn how to use Nyckel as an alternative to Google Vision API.
## Pre-requisites
:::success
- Knowledge of Python
- Understanding of Machine learning
- A web-browser (Chrome is adviseable)
- Python Software which you can get [here](https://www.jetbrains.com/pycharm/download/#section=windows)
:::
## What is Google Vision API?
Google Vision API is an Image Analysis tool that is powered by machine learning which is developed by Googe (a well-known tech company).
Google Vision API enables software developers to build an application that can be integrated with vision detection features in images, such as objects, faces, text, and logos.
### Uses Of Vision API
Vision API is well known for caryying out task with accurate and precise result. Below are the core aspetc where Vision API is mostly used and generated accurate result.
:::success
- **Face Recognition:** When an image or set or images were uploaded, Vision Api is used to detect the type of faces present in the imgaes. It also consist of a broad application like a surveillance system.
- **Optical Character Recognition(OCR):** THis is a typical illustration of Computer Vision which main objective is to extract text from an image.
- **Image Properties Detection:** As it sounds, Vision API is also used to detect image properties such as color.
- **Label Detection:** Vision API can also be used to annotates an image with a label with respect to the image contents. The label can indetify range of things such as `locations`, `activities`, `objects`, `species of animals` ,`humans`, `facial expressions`, `animals` and `products`.
:::
Google Vision API is a very popular tool that is very easy to integrate into your application even if you don't have a solid knowledge of Machine Learning.
It is widely used in various tools and frameworks which include Python, PHP, Java, Ruby, Node.js and C#.
It is widely use in various tools and frameworks which include `Python`, `PHP`, `Java`, `Ruby`, `Node.js` and `C#`.
## Illustration on How to Use Vision AI
You might be wondering how Google Vision API works out! Right? Don't worry, I am going to take you through a real example using the Google Vision AI Homepage.
- Navigate to [Google Vision AI](https://cloud.google.com/vision) page using your Chrome browser.
- scrolled down a little bit till you found a sub-section called **Try the API**
- This section containg a box which allow you to drag/upload an image of your choice on its interface as show below:

- Once you upload an image, it will provide you some information by pefroming some task namely Image recognition, Labelling, Image properties.

As shown in the image above, Vision AI detected a lot of information about the image. It accurately named the image as a Cat with 80% accuracy and precision. Isn't it Fascinating? You can explore the other tabs such as labels and properties to learn more about the image.
### Labels Google Vision API Can Return
The API is well known to have a wide range of labels it can work with which makes it user-friendly and easily chosen by most developers. According to a [research](https://stackoverflow.com/questions/38363182/is-there-a-full-list-of-potential-labels-that-googles-vision-api-will-return) carried out by James Cameroon, [Google open images](https://storage.googleapis.com/openimages/web/index.html) consist of list that is slightly above 20k classifications.
The list of labels the API can return include but not limited to:
| OpenImages Classification | I.D |
|:-------------------------:|:--------:|
| Air conditioning | 01127 |
| Airmail | 01_097 |
| Roller coaster | 010l12 |
| Witch hat | 010lq47b |
| Bun (Food) | 0119x1zy |
| Water bottle | 0118n_9r |
| Reflex camera | 0118ms9c |
| Plantation | 011yvr |
| Pencil skirt | 01172_8x |
| Stained glass | 011y23 |
| Sea turtle | 0120dh |
| Electronic instrument | 0121tl |
| Football | 01226z |
| Container | 011q46kg |
| Amusement park | 010jjr |
You can have access to the full list by downloading the file [here](https://storage.googleapis.com/openimages/web/download.html)
## Using Python as Vision API Client Library
Now, you understand that Vision API can be used to request some piece of information from an image such as label detection. You might be wondering how to go about it! To achieve this, You will need to use a **Client library**. Examples of such libraries are `Python`, `Java`, `Node.js` and `GO`.
However, I am going to be using `python` as our **Client library**. Dont be baffled, the syntax is going to be fun and simple.
:::success
:bulb: **Note:** Take carefull consideration of the **indentation** used in all the code written. It is highly important when using Python.
:::
Now, the first procedure is to install the Python variant of the Google Vision API which can be achieve using `pip`.
```python=9
pip install --upgrade google-cloud-vision
```
Now that your installation is succesful, the next step is to verify it by importing the **Google Cloud** client library as shown below
```python=9
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
```
Now you will build an application by writing some code, this application will be used to recognize and detect some general features of an Image such as color, animals, and locations.
To achieve this, the intended image will be stored inside the computer that will be used to run the application. You will now insert the **path of the image** as an `input` into the application.
Fistly, you will need to **Instantiates a client** by using `ImageAnnotatorClient()`. This syntax contain the utilities that are used for extracting image properties.
```python=9
client = vision.ImageAnnotatorClient()
```
Now you will create a variable that will contain the filename of the image to annotate and also its folder directory.
```python=9
file_name = os.path.abspath(imageML/siberiancat.jpg')
```
Then you will load the image into your workspace memory using io.open which contain **two arguments** which are the `file_name` and `rb`.
```python=9
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
```
The next step is for you to instantiate an object by using the code `vision.types.image` which will take `content=content` as it's **argument**.
```python=9
image = vision.types.Image(content=content)
```
Now, you are going to write a code that will perform label detection on the image file.
:::success
:Bulb: **To achieve this, you will need to :**
- call `client.label_detection` which will take `image=image` as an **arguments**
- Then you will create a variable called `response` which will be used to save the result of `clients.label_detection`.
- Now, the image properties will be extracted by using `response.label_annotations` which will be saved in another variable called `label`
:::
```python=9
response = client.label_detection(image=image)
labels = response.label_annotations
```
Finaly, you will need to print the label description using a **for loop** as shown in the code written below
```python=9
print('Labels:')
for label in labels:
print(label.description)
```
## Other Types of API.
I believe by now you have acquired some little knowledge about Google Vision API. However, Google Vision API is not the only API developers can use. Other APIs can conveniently perform the same task as google vision API producing accurate and precise results.
An example of such API is **Nyckel**. It sounds strange to you, right? Don't be scared it's quite easy to use and integrate into your workspace.
Now lets dive in.
### What is Nyckel?
**Nyckel** is a **Machine Learning API** that allows developers to train and integrate ultra-modern and sophisticated machine learning into their applications within a fraction of a second.
It is built in such a way that it can be used effortlessly by developers and non-expert to provide **automated training** to their models instead of brainstorming themselves to write codes manually.
## How to Train Nyckel and Intergrate it Into Your Application
Now, I will take you through on a step by step guide on how you can train Nyckel to recognize and label an object or animal and then detect it with great precision the next time it came across anything similar to it.
It going to be fun and exciting, Now let's get Started.
### Step 1
**Create a Nyckel account**
To use Nyckel API to train you model, you will need to create a simple personal account. Use your Chrome browser to sign up on [Nyckel](https://www.nyckel.com/)
### Step 2
Click on `new function` as shown below

Then u will click on `images` , Scroll down a bit and you will see a sub-heading called **Output Label**. Here you will create a label name(such as `Animal`, `Object`, `Human`) which you want to train the API to recognize when an image is uploaded
:::success
:Bulb: **Note** - You can create additional label name as much as you like, It depends on the range of information you want to train the API with.
:::

Now Click on `create function`.
### Step 3
You will now upload different kind of images you want to train the API to recognize

Now Click on `import` in blue button.
### Step 4
The Next step is to train the API by assigning the corresponding`label names` to each images you uploaded.

Then click on `invoke`.
### Step 5
You have completed training the API to recognized and Label images.
Now you will test it by uploading a new random image and click on the `invoke` button.
As shown below, I uploaded an image of a **baby**, and it was labelled as `Human` with `0.7736` Confidence as shown under the function output.

### Step 6

Along with the Function Output which contain a `LabelName` and `Confidence` level, **Nyckel API** also generated an **automatic code** which developers can use by integrating it into their application instead of writing out the code manually.
```python=9
import requests
url = 'https://www.nyckel.com/v1/functions/tawetnxnruod16gh/invoke'
headers = {
'Authorization': 'Bearer ' + 'eyJhbGciOiJSUzI1NiIsInR5cCI6ImF0K2p3dCJ9.eyJuYmYiOjE2ODIzNzIzMDUsImV4cCI6MTY4MjM3NTkwNSwiaXNzIjoiaHR0cHM6Ly93d3cubnlja2VsLmNvbSIsImNsaWVudF9pZCI6ImhyamY5Y2NrNXkxbzBoaWl1cXdhczk1dXJxYTExYjhvIiwianRpIjoiMUZBNjYxOEZFMDI0RjFCMUM2NTA1NjdFRTVFQTE2RDIiLCJpYXQiOjE2ODIzNzIzMDUsInNjb3BlIjpbImFwaSJdfQ.f0ZcukpCyunQez4UucCcE6gPqDZ68qSlJyURZCq3spEn4Hp6Da0C7dLLsaD0vGtBVLt_mTlF7AI3X4wvoEfioM5SrrT4Pn8p2OF4T3CdA3QWIiLcCMv2fNE6baaRqyYZ1qjt9JF-Bky8VFkxm4DQTovFxCwm98x0ZrvjHsinoMPf-hYnHazrDOBEjH2TPSSUlQVbalUOpGiVlpcZUANI8AXLjYCva3XCJL9qxI3rMMrbG5vdx2jRum6Dv0SxflykRLEjxYqxPe3y0UNWvuTF15Pl0ACHpu0XRKO6WOR4-RZaq_h_4zyXg3jTeIExxlUigHr9I9fzf3CyEunnpANARw',
}
with open('baby.jpg', 'rb') as f:
result = requests.post(url, headers=headers, files={'data': f})
print(result.text)
```
## Conclusion
Due to Google's popularity as a giant tech company, Google Vision API is widely used among developers. But with this article, you can see that Nyckel is a great and powerful tool that can perform exactly the task carried out by Google Vision API.
Google Vision API can be difficult to use for non-expert or developers that do not have deep knowledge of programming and machine learning.
However, Nyckel makes it much easier for a non-expert to train the API to recognize images and be easily integrated into their application through the code that is auto-generated by Nyckel.
It's highly appropriate to conclude that Nyckel is a wonderful API that can be used as an alternative to Google Vision API for developers and non-expert.