LandingEdge APIs
  • 21 Dec 2022
  • 2 Minutes to read
  • Dark
    Light
  • PDF
  This documentation version is deprecated, please click here for the latest version.

LandingEdge APIs

  • Dark
    Light
  • PDF

Article summary

Overview

You can use a Web API to send images to your Inspection Point in LandingEdge. To do this, your Inspection Point must first be set up with Web API as the Media Source.

WebAPI Configuration in LandingEdge

Web API Endpoints

The Web API provides three possible endpoints you can use. All three of them return the predictions as JSON.

Swagger Documentation

To access the LandingEdge Swagger API documentation, go to this website: http://localhost:[port#]/docs, where you use the same port number you entered in LandingEdge. For example, if you entered 7054 as your port number, you would go to this website: http://localhost:7054/docs.

Port Number in LandingEdge 

Postman Example

  • When to Use: You want to use Postman to test the API.

Postman API Example

cURL Request Example

  • When to Use: When you want to make a request from the command line.
curl -X 'POST' \
  'http://localhost:<webAPI port entered in configuration>/images' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@sample.jpg;type=image/jpeg'

/Images Example

  • When to Use: The images you want to run inference on are already on disk.
import json
from mimetypes import guess_type
from pathlib import Path
from typing import Any, Union

import requests


def infer(filename: Union[Path, str], port: int) -> Any:
    """
    Run inference on an image using the /images endpoint
    :param filename: path to the image file
    :param port: port number from LandingEdge Web API configuration
    :return: object representing the inference results
    """
    # LandingEdge app url construction
    windows_app_url = f"http://127.0.0.1:{port}/images"

    # Send the request
    with open(Path(filename).resolve(), "rb") as f:
        files = [("file", (Path(filename).name, f, guess_type(filename)))]
        response = requests.post(
            windows_app_url,
            files=files)

    return json.loads(response.text)

/RGBB24mmf Example

  • When to Use: You have images already in the computer's memory.
  • Prerequisites: You have a great understanding of scripting in Python.

The /RGBB24mmf option uses a local memory-mapped file (MMF) to upload images, rather than sending a copy.

Note:
The RGBB24mmf API requires images to be on the same system that you are calling the API from. If the images are on a separate system, you cannot call this API.
import json
import mmap
import uuid
from typing import Any

import requests
from nptyping import ndarray


def infer(image: ndarray, port: int) -> Any:
    """
    Run inference on an image using the /RGB24mmf endpoint
    :param image: numpy array representing the image. Must be RGB ordering
    :param port: port number from LandingEdge Web API configuration
    :return: object representing the inference results
    """
    # LandingEdge app url construction
    windows_app_url = f"http://127.0.0.1:{port}/RGB24mmf"

    # retrieve information about the image
    height, width, _ = image.shape

    # Send the request
    tag_name = str(uuid.uuid4())
    with mmap.mmap(-1, height * width * 3, tagname=tag_name) as mm:
        mm.write(image.tobytes())
        response = requests.post(
            windows_app_url,
            files={
                "mmf": (None, tag_name),
                "height": (None, height),
                "width": (None, width),
            },
        )

        return json.loads(response.text)

/RGBB24Raw Example

If you want to use the /RGBB24Raw API, you may need to manipulate the image, as shown in the example below.

import json
import uuid
from typing import Any

import requests
from nptyping import ndarray


def infer(image: ndarray, port: int) -> Any:
    """
    Run inference on an image using the /RGB24raw endpoint
    :param image: numpy array representing the image. Must be RGB ordering
    :param port: port number from LandingEdge Web API configuration
    :return: object representing the inference results
    """
    # LandingEdge app url construction
    windows_app_url = f"http://127.0.0.1:{port}/RGB24raw"

    # retrieve information about the image
    height, width, _ = image.shape

    # Send the request
    tag_name = str(uuid.uuid4())

    files = {"width": (None, width),
             "height": (None, height),
             "file": (tag_name, image.tobytes())}

    response = requests.post(
        windows_app_url,
        files=files)

    return json.loads(response.text)



Was this article helpful?