>
>
>
# OpenCV test application
This section describes how to enable OpenCV library and run OpenCV test application
## Prerequisites
- Set up your infrastructure as described in the [Qualcomm Linux Build Guide](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-254/introduction.html)
- Flash the latest software release to the development board.
- Set up SSH connection:
1. Enable SSH in Permissive mode by performing the steps mentioned in [Use SSH](https://docs.qualcomm.com/bundle/publicresource/topics/80-70015-254/how_to.html#use-ssh)
2. Connect to the device by running the following command:
ssh root@
Copy to clipboard
For example, if the IP address of the device is `10.92.160.222`, run the following command:
ssh root@10.92.160.222
Copy to clipboard
## Enable OpenCV library and test package
1. To enable the **tests** package, include `tests` in
`PACKAGECONFIG` in the
`/layers/meta-qcom-hwe/recipes-support/opencv/opencv_4.10.0.qcom.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
By default, only libraries shown in the compiled build as test bins are cleaned up.
2. To retain test bins, include the following code in the
`/layers/meta-qcom-hwe/recipes-support/opencv/opencv_4.10.0.qcom.bb` recipe file:
RM_WORK_EXCLUDE += "opencv"
Copy to clipboard
3. 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
During compilation no code is modified; so a direct compilation does not generate the corresponding bins.
4. 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.10.0.qcom-r0\build\bin`.
## Run test application
To invoke the OpenCV API, native OpenCV test examples can reference sample applications. 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-70015-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.10.0](https://github.com/opencv/opencv_extra/tree/4.10.0).
3. To avoid read only errors while trying to push test data and bins to the device, use the device IP address to log in to an SSH terminal 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. Log in to an SSH terminal and run the following commands.
chmod 777 /usr/bin/
root@qcm6490:~# cd /usr/bin
export OPENCV_LOG_LEVEL=DEBUG
export OPENCV_VIDEOIO_DEBUG=1
export OPENCV_TEST_DATA_PATH=/tmp
./ --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.
## How to measure FastCV HAL vs OpenCV performance
Compile the build with either of the following options
- To enable FastCV acceleration, use the `-DWITH_FASTCV=ON` option
- To enable default OpenCV on CPU, use the `-DWITH_FASTCV=OFF` option
Note
By default OpenCV acceleration with FastCV is enabled.
Once compilation is done, flash the build and boot the device.
All libraries are present in the `/usr/lib/` directory.
1. Copy the test bins to `/usr/bin` to run the tests.
scp -r opencv_perf_core root@[IP-address]:/usr/bin/
Copy to clipboard
2. To start the test on the target device, run the following commands.
cd /usr/bin/
Copy to clipboard
chmod 777 opencv_perf*
Copy to clipboard
export OPENCV_OPENCL_RUNTIME=disabled && export OPENCV_TEST_DATA_PATH=/tmp && /usr/bin/opencv_perf_core --gtest_filter=ArithmMixedTest.subtract/2 --perf_min_samples=100 --perf_force_samples=100 >> results_Arithm.txt
Copy to clipboard
The above commands run different test cases for the subtract API, with each test case looped over 100 times.
The results are collected in a `results_Arithm.txt` text file.
`results_Arithm.txt` includes details for different test cases including the test name, number of samples, resolution, mean time,
pass/fail status. For the following test case with FastCV acceleration enabled, the total time taken was **16 ms**.

**FastCV performance results**
With the default OpenCV, for the same test case, the total time taken was 23 ms.

**OpenCV performance results**
Run other test cases and compare the latency numbers between default OpenCV and FastCV accelerated OpenCV.
## Supported OpenCV APIs and corresponding FastCV APIs
| OpenCV module | OpenCV API | Underlying FastCV API for OpenCV acceleration |
| --- | --- | --- |
| IMGPROC | medianBlur | fcvFilterMedian3x3u8\_v3 |
| IMGPROC | sobel | fcvFilterSobel3x3u8s16 |
| IMGPROC | sobel | fcvFilterSobel5x5u8s16 |
| IMGPROC | sobel | fcvFilterSobel7x7u8s16 |
| IMGPROC | boxFilter | fcvBoxFilter3x3u8\_v3 |
| IMGPROC | boxFilter | fcvBoxFilter5x5u8\_v2 |
| IMGPROC | adaptiveThreshold | fcvAdaptiveThresholdGaussian3x3u8\_v2 |
| IMGPROC | adaptiveThreshold | fcvAdaptiveThresholdGaussian5x5u8\_v2 |
| IMGPROC | adaptiveThreshold | fcvAdaptiveThresholdMean3x3u8\_v2 |
| IMGPROC | adaptiveThreshold | fcvAdaptiveThresholdMean5x5u8\_v2 |
| IMGPROC | subtract | fcvImageDiffu8f32\_v2 |
| CORE | lut | fcvTableLookupu8 |
| CORE | norm | fcvHammingDistanceu8 |
| CORE | multiply | fcvElementMultiplyu8u16\_v2 |
| CORE | transpose | fcvTransposeu8\_v2 |
| CORE | transpose | fcvTransposeu16\_v2 |
| CORE | transpose | fcvTransposef32\_v2 |
| CORE | meanStdDev | fcvImageIntensityStats\_v2 |
| CORE | flip | fcvFlipu8 |
| CORE | flip | fcvFlipu16 |
| CORE | flip | fcvFlipRGB888u8 |
| CORE | rotate | fcvRotateImageu8 |
| CORE | rotate | fcvRotateImageInterleavedu8 |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| OpenCV extension APIs | FastCV APIs used | Description |
| --- | --- | --- |
| matmuls8s32 | fcvMatrixMultiplys8s32 | Matrix multiplication of two int8\_t type matrices |
| clusterEuclidean | fcvClusterEuclideanu8 | General function for computing cluster centers and cluster bindings |
| FAST10 | fcvCornerFast10InMaskScoreu8 | Extracts FAST corners and scores from the image based on the mask.
Source msut be 8-bit grayscale image where keypoints are detected |
| FAST10 | fcvCornerFast10InMasku8 | Extracts FAST corners from the image. |
| FAST10 | fcvCornerFast10Scoreu8 | Extracts FAST corners and scores from the image |
| FAST10 | fcvCornerFast10u8 | Extracts FAST corners from the image. |
| FFT | fcvFFTu8 | Computes the 1D or 2D Fast Fourier Transform of a real valued matrix. |
| IFFT | fcvIFFTf32 | Computes the 1D or 2D Inverse Fast Fourier Transform of a complex valued matrix. |
| fillConvexPoly | fcvFillConvexPolyu8 | This function fills the interior of a convex polygon with the specified color. |
| houghLines | fcvHoughLineu8 | Performs Hough Line detection |
| moments | fcvImageMomentsu8 | Computes weighted average (moment) of the image pixels’ intensities
Source pointer to the original Input must be of data 8-bit image. |
| moments | fcvImageMomentss32 | Computes weighted average (moment) of the image pixels’ intensities
Source Pointer to the original input must be of data type int32\_t. |
| moments | fcvImageMomentsf32 | Computes weighted average (moment) of the image pixels’ intensities
Source pointer to the original Input must be of data type float32\_t. |
| runMSER | fcvMserInit | Function to initialize MSER. |
| runMSER | fcvMserNN8Init | Function to initialize 8-neighbor MSER |
| runMSER | fcvMserExtu8\_v3 | Function to invoke MSER with a smaller memory footprint, the (optional) output of contour bound boxes, and additional information. |
| runMSER | fcvMserExtNN8u8 | Function to invoke 8-neighbor MSER, , with additional outputs for each contour. |
| runMSER | fcvMserNN8u8 | Function to invoke 8-neighbor MSER. |
| runMSER | fcvMserRelease | Function to release MSER resources. |
| remap | fcvRemapu8\_v2 | Applies a generic geometrical transformation to a greyscale CV\_8UC1 image. |
| remapRGBA | fcvRemapRGBA8888BLu8 | Applies a generic geometrical transformation to a 4-channel CV\_8UC4 image with bilinear interpolation |
| remapRGBA | fcvRemapRGBA8888NNu8 | Applies a generic geometrical transformation to a 4-channel CV\_8UC4 image with nearest neighbor interpolation |
| resizeDownBy2 | fcvScaleDownBy2u8\_v2 | Down-scale the image by averaging each 2x2 pixel block |
| resizeDownBy4 | fcvScaleDownBy4u8\_v2 | Down-scale the image by averaging each 4x4 pixel block |
| meanShift | fcvMeanShiftu8 | Applies the meanshift procedure and obtains the final converged position.
Source image must be 8 bit grayscale image. |
| meanShift | fcvMeanShifts32 | Applies the meanshift procedure and obtains the final converged position.
Source image must be int 32bit grayscale image. |
| meanShift | fcvMeanShiftf32 | Applies the meanshift procedure and obtains the final converged position.
Source image must be float 32bit grayscale image. |
| bilateralRecursive | fcvBilateralFilterRecursiveu8 | Here the smoothing is actually performed in gradient domain. |
| thresholdRange | fcvFilterThresholdRangeu8\_v2 | Binarizes a grayscale image based on a pair of threshold values. |
| bilateralFilter | fcvBilateralFilter5x5u8\_v3 | Bilateral smoothing with 5x5 bilateral kernel |
| bilateralFilter | fcvBilateralFilter7x7u8\_v3 | Bilateral smoothing with 7x7 bilateral kernel |
| bilateralFilter | fcvBilateralFilter9x9u8\_v3 | Bilateral smoothing with 9x9 bilateral kernel |
| | | |
| | | |
| | | |
| | | |
| | | |
For FastCV Extension details, see [https://docs.opencv.org/4.x/dc/db8/group__fastcv.html](https://docs.opencv.org/4.x/dc/db8/group__fastcv.html)
## Enable or disable FastCV acceleration
Enable
Enable FastCV HAL acceleration by including **-DWITH\_FASTCV=ON** in the OpenCV bitbake file in the
**EXTRA\_OECMAKE** options as shown below.
This flag allows compilation of OpenCV APIs with the FastCV HAL.
DEPENDS:qcom-custom-bsp += "qcom-fastcv-binaries"
EXTRA_OECMAKE += "-DOPENCV_ALLOW_DOWNLOADS=ON"
EXTRA_OECMAKE:append:qcom-custom-bsp = " -DWITH_FASTCV=ON "
#python () {
Copy to clipboard
Disable
Disable FastCV HAL acceleration by including **-DWITH\_FASTCV=OFF** in the OpenCV bitbake file in the
`EXTRA_OECMAKE` options as shown below and then recompile the OpenCV recipe using the devtool method.
DEPENDS:qcom-custom-bsp += "qcom-fastcv-binaries"
EXTRA_OECMAKE:append:qcom-custom-bsp = " -DWITH_FASTCV=OFF "
#python () {
# bsp_type = d.getVar('BSP_TYPE')
Copy to clipboard
The following shows how this flag is included in the CMakeLists files (`opencv/3rdparty/fastcv/CMakeLists.txt`):
if(NOT WITH_FASTCV OR NOT FASTCV_DIR)
message(STATUS "FastCV is not available, disabling related HAL and stuff")
return()
endif()
if(NOT ANDROID AND NOT UNIX)
message(FATAL_ERROR "FastCV HAL supports Android and UNIX only!")
endif()
set(OPENCV_3P_FASTCV_DIR ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(hal)
Copy to clipboard
The following sample is one of the FastCV HAL API implementations with FastCV APIs.
`opencv/3rdparty/fastcv/src/fastcv_hal_core.cpp`
int fastcv_hal_sub8u32f(
const uchar* src1_data,
size_t src1_step,
const uchar* src2_data,
size_t src2_step,
float* dst_data,
size_t dst_step,
int width,
int height)
{
INITIALIZATION_CHECK;
fcvStatus status = FASTCV_SUCCESS;
if (src1_step < width && src2_step < width)
{
src1_step = width*sizeof(uchar);
src2_step = width*sizeof(uchar);
dst_step = width*sizeof(float);
}
status = fcvImageDiffu8f32_v2(src1_data, src2_data, width, height, src1_step,
src2_step, dst_data, dst_step);
CV_HAL_RETURN(status,hal_subtract);
}
Copy to clipboard
Last Published: Dec 27, 2024
[Previous Topic
Getting Started](https://docs.qualcomm.com/bundle/publicresource/80-70017-21/topics/getting-started.md) [Next Topic
References](https://docs.qualcomm.com/bundle/publicresource/80-70017-21/topics/references.md)
Source: [https://docs.qualcomm.com/doc/80-70017-21/topic/samples.html](https://docs.qualcomm.com/doc/80-70017-21/topic/samples.html)