PEKAT VISION SDK - Python¶
A Python module for communication with PEKAT VISION.
Installation¶
pip install "pekat-vision-sdk[opencv]"
- recommendedpip install pekat-vision-sdk
- wihoutopencv
, click here for more
Usage¶
Using this SDK involves 3 basic steps:
Creation¶
Create an Instance to start a project or connect to an already running project:
from pathlib import Path
from PekatVisionSDK import Instance
# Start a project on port 8000
p = Instance(Path.home() / "PekatVisionProjects/myProject", port=8000)
from PekatVisionSDK import Instance
# Connect to a project running on port 8000
p = Instance(port=8000, already_running=True)
Analysis¶
Call the analyze method and supply it with the image, either as a numpy array, bytes or a path on disk:
import cv2
# Load an image as a numpy array
image = cv2.imread("path_to_image.png")
result = p.analyze(image)
from pathlib import Path
# Load a png
image_bytes = Path("path_to_image.png").read_bytes()
result = p.analyze(image_bytes)
# Instance will load the image as bytes
result = p.analyze("path_to_image.png")
Depending on the response type, the image may or may not be present in the result, see analyze for more.
Processing¶
The result contains an encoded PNG image and the context dictionary.
In case response type was "context"
, image_bytes
will be None
and get_decoded_image will raise an exception.
Processing the result
# Getting the context
context = result.context
# Getting the result of evaluation
evaluation_result = context["result"]
# Getting the numpy image
try:
image = result.get_decoded_image()
except ValueError:
print("analyze called with response_type='context'")
# In case we need just PNG bytes
image_bytes = result.image_bytes # This can be None
Without OpenCV¶
You can install this module without OpenCV if you
- only want to use
response_type="context"
- don't need to use
Result.get_decoded_image()