# Interfaces

OpenCV is a versatile [open-source software library](http://opencv.org) that provides a wide range of
functions in the form of hundreds of computer vision algorithms to empower developers to
build sophisticated computer vision applications across domains. With this extensive collection of optimized
algorithms, OpenCV is frequently used by CV developers.

Operations such as applying filters on images, feature extraction, image segmentation,
pattern recognition, machine learning, and deep learning on visual data (images, videos, and so on) use
[OpenCV](https://docs.opencv.org/4.x/d9/df8/tutorial_root.html)
to help computers realize vision functionalities that include object detection and tracking, scene and image understanding
and classification, face detection and recognition, and gesture recognition.

Note

Prior to running an SSH command, ensure that you enable SSH in the Permissive mode by following the steps in the [How to SSH](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-254/how_to.html#how-to-ssh-)
Section of the [Qualcomm Linux Build Guide](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-254/)

## Compile and incorporate OpenCV 4.5.5 into your framework

1. Sync and build the latest Qualcomm Linux software release using the Yocto workflow as described in the
[Qualcomm Linux Build Guide](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-254/) (80-70014-254).
2. Flash the latest Qualcomm Linux software release as described in the
[Qualcomm Linux Build Guide](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-254/) (80-70014-254).
3. To enable the **tests** package, include `tests` in
`PACKAGECONFIG` in the
`<workspace>/layers/meta-openembedded/meta-oe/recipes-support/opencv/opencv_4.5.5.bb`
recipe file as follows.

PACKAGECONFIG ??= "gapi python3 eigen jpeg png tiff v4l libv4l samples tbb gphoto2 tests \
        ${@bb.utils.contains("DISTRO_FEATURES", "x11", "gtk", "", d)} \
        Copy to clipboard

**Libraries and test applications**

By default, only libraries shown in the compiled build as test bins are cleaned up.

1. To retain test bins, include the following code in the
`<workspace>/meta-openembedded/meta-oe/recipes-support/opencv/opencv_4.5.5.bb` recipe file:

RM_WORK_EXCLUDE += "opencv"
        Copy to clipboard
2. When the build is already compiled, OpenCV must be cleaned before compilation.
To clean OpenCV, run the following command:

bitbake -fc cleanall opencv
        Copy to clipboard

    There are no code modifications during compilation, so a direct compilation does not generate the corresponding bins.
3. To compile OpenCV, run the following command:

bitbake opencv
        Copy to clipboard

The path to the libraries is `tmp-glibc/sysroots-components/armv8-2a/opencv/usr/lib/`.

The path to the bins is `tmp-glibc/work/armv8-2a-qcom-linux/opencv/4.5.5-r0/build/bin/`.

## Testing

Sample applications to invoke the OpenCV API can be referred to from the native OpenCV
test examples. Use the following procedure to invoke applications on the Snapdragon target.

Compile the full build image to ensure that all libraries are part of the application images.

1. Flash the images on the device as described in the [Qualcomm Linux Build Guide](https://docs.qualcomm.com/bundle/publicresource/topics/80-70014-254/) (80-70014-254).

    OpenCV libraries are on the device at `/usr/lib`.
2. For test data, Git clone the projects at [https://github.com/opencv/opencv_extra/tree/4.5.5](https://github.com/opencv/opencv_extra/tree/4.5.5).
3. To avoid read only errors while trying to push test data and bins to the device, log in to an SSH terminal using the device IP address and run the following command to remount the device.

mount -o remount,rw /
        Copy to clipboard
4. Use the `scp` command to push the test data to a preferred host location.

    For example: `scp -r [file] root@[IP-ADDR]:/tmp`
5. Use the `scp` command to push the required test bin to `/usr/bin`.

    For example: `scp -r [test] root@[IP-ADDR]:/usr/bin/`
6. Execute the following commands on the host.

scp -r tmp-glibc/sysroots-components/armv8-2a/opencv/usr/lib/libopencv_ts.so root@[IP-ADDR]:/usr/lib/
        scp -r tmp-glibc/sysroots-components/armv8-2a/opencv/usr/lib/libopencv_ts.so.4.5.5 root@[IP-ADDR]:/usr/lib/
        scp -r tmp-glibc/sysroots-components/armv8-2a/opencv/usr/lib/libopencv_ts.so.405 root@[IP-ADDR]:/usr/lib/
        Copy to clipboard
7. Log in to an SSH terminal and run the following commands.

chmod 777 /usr/bin/<opencv_test_bin>
        cd usr/bin
        export OPENCV_LOG_LEVEL=DEBUG
        export OPENCV_VIDEOIO_DEBUG=1
        export OPENCV_TEST_DATA_PATH=/tmp
        ./<opencv_test_bin> --gtest_output=json:/tmp/results.json --gtest_also_run_disabled_tests
        exit
        Copy to clipboard

    Results are stored in `/tmp/results.json`.
To change the results filename, modify the
`--gtest_output=json:/tmp/results.json` argument.

Last Published: Jul 08, 2024

[Previous Topic
Overview](https://docs.qualcomm.com/bundle/publicresource/80-70014-21/topics/overview.md) [Next Topic
Sample application](https://docs.qualcomm.com/bundle/publicresource/80-70014-21/topics/samples.md)