5 G API Python Bindings
Dmitry Matveev edited this page 2023-05-27 10:11:15 +01:00

Intro

G-API is also available in OpenCV for Python. This page explains how to build and test G-API in Python.

Requirements

  • Python3+ with numpy
  • OpenVINO - for inference tests with OpenVINO backend;
  • ONNX RT - for inference tests with ONNX Runtime backend;
  • Working videoio module - built with either FFMPEG or GStreamer support - as some tests are using video files as input.

Building

Use this CMake option to enable Python (make sure to include options for OpenVINO and ONNX RT if necessary):

$ cmake /path/to/opencv -DWITH_PYTHON=ON -DCMAKE_BUILD_TYPE=Release
$ make -j8 opencv_python3

Testing

Setup environment:

$ export LD_LIBRARY_PATH=<path-to-opencv-build>/lib/:$LD_LIBRARY_PATH
$ export PYTHONPATH=<path-to-opencv-build>/python_loader/:$PYTHONPATH
$ export OPENCV_TEST_DATA_PATH=<path-to-opencv_extra>/testdata/
$ export OPENCV_DNN_TEST_DATA_PATH=<path-to-opencv_extra>/testdata/dnn

Now run G-API tests:

$ cd <path-to-opencv-build>
$ OPENCV_PYTEST_FILTER=test_gapi* python3 <path-to-opencv-root>/modules/python/test/test.py