LandingEdge APIs
  • 19 Sep 2023
  • 2 Minutes to read
  • Dark
    Light
  • PDF

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 Media Source must be set to Web API.

WebAPI Configuration in LandingEdge

Web API Endpoints

The Web API provides the following possible endpoints you can use. All endpoints 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 that you entered in LandingEdge. For example, if you entered 7054 as your port number, then 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 ExamplePostman 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)

/RGB24mmf Example

Note:
The /RGB24mmf endpoint is only available on Windows. 

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

The RGB24mmf 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.

  • When to Use: You have images already in the computer's memory.
  • Prerequisites: You have a great understanding of scripting in Python.
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)

Was this article helpful?

What's Next