Use Microsoft image recognition in order to identify production error in Dynamics365 Manufacturing

by | Sep 16, 2022

Microsoft Cognitive Services provides a suite of pre-built APIs that can be used for image recognition. One of these APIs, the Computer Vision API, can be used to identify production errors in Dynamics 365 Manufacturing. By analyzing images of products and production lines, businesses can quickly and accurately identify errors and take corrective action.

In this article, we will explore how to use Microsoft image recognition to identify production errors in Dynamics 365 Manufacturing.

Step 1: Setting up the Microsoft Cognitive Services API

To get started, we need to set up an account with Microsoft Cognitive Services and obtain an API key. Follow the steps below:

  1. Go to the Microsoft Cognitive Services website and sign up for an account.
  2. Once you have signed up, you will be directed to the dashboard. From here, click on “Create a resource”.
  3. Select “AI + Machine Learning” and choose “Computer Vision” from the available options.
  4. Fill in the required information and select a pricing tier that meets your needs.
  5. Once you have completed the setup, you will be provided with an API key that you can use to access the Computer Vision API.

Step 2: Setting up the Python Environment

Next, we need to set up our Python environment. We will be using the requests and json modules in Python for this task. If you do not have these modules installed, you can install them using pip. Run the following command:

pip install requests json

Step 3: Analyzing Images and Identifying Production Errors

Now that we have set up our Microsoft Cognitive Services API and Python environment, we can start analyzing images and identifying production errors. We will be using the Computer Vision API for this task.

First, we need to create a function that will take an image file as input and return the identified production errors. Here’s an example:

import requests

import json

def identify_production_errors(image_path, api_key):

    headers = {

        ‘Content-Type’: ‘application/octet-stream’,

        ‘Ocp-Apim-Subscription-Key’: api_key,

    }

    with open(image_path, ‘rb’) as f:

        data = f.read()

    response = requests.post(“https://<REGION>.api.cognitive.microsoft.com/vision/v3.2/analyze?visualFeatures=Objects&details=Landmarks&language=en”, headers=headers, data=data)

    errors = []

    if response.status_code == 200:

        response_data = json.loads(response.content.decode(‘utf-8’))

        for obj in response_data[‘objects’]:

            if obj[‘object’] == ‘defect’:

                errors.append(obj[‘property’][‘type’])

    return errors

The function takes two parameters: the path to the image file and the API key. It then creates the required headers and data for the Computer Vision API and sends a POST request to the API endpoint. The function then extracts the identified production errors from the API response and returns them.

To use this function, simply call it with the image file path and API key as parameters:

image_path = “product_image.jpg”

api_key = “<YOUR_API_KEY>”

errors = identify_production_errors(image_path, api_key)

print(errors)

This will output a list of identified production errors, if any.

Conclusion

Microsoft image recognition can be a powerful tool for identifying production errors in Dynamics 365 Manufacturing. By using the Computer Vision API to analyze images of products and production lines, businesses can quickly and accurately identify errors and take corrective action. With just a few lines of code, businesses can leverage the power of Microsoft image recognition to improve their manufacturing processes and increase efficiency.