# Sample applications ## Implement and deploy OpenCV sample application Page-1 Rectangle.8 Sheet.2 Prerequisites Prerequisites Sheet.3 Generate SDK Install SDK · Generate SDK· Install SDK Sheet.4 Implement Implement Sheet.6 Test Test Sheet.11 Sheet.13 Sheet.14 Implement application Compile application · Implement application· Compile application Sheet.15 Run application · Run application ## Prerequisites - Install the Platform SDK using either of the following methods: - [Using the Qualcomm release archive](https://docs.qualcomm.com/doc/80-80022-51/topic/install-sdk.html) - [Manually compiling the Qualcomm Linux SDK](https://docs.qualcomm.com/doc/80-80022-254/topic/how_to.html#generate-an-sdk) ## Implement OpenCV rotate application with FastCV See [OpenCV rotate()](https://docs.qualcomm.com/doc/80-80022-21/topic/sample-applications.html#opencv-rotate) for API usage details. 1. Go to your SDK installation path on the Linux host and set the SDK environment by running the following command: source environment-setup-armv8a-qcom-linux Copy to clipboard 2. Run the following command to set the SDKTARGETSYSROOT. export SDKTARGETSYSROOT={}/sysroots Copy to clipboard 3. Run the following commands to create and change the `/opencv_rotate/` directory in the SDK install directory. mkdir opencv_rotate cd opencv_rotate Copy to clipboard 4. Create the following [configure.ac](https://docs.qualcomm.com/doc/80-80022-21/topic/sample-applications.html#configureac3), [Makefile.am](https://docs.qualcomm.com/doc/80-80022-21/topic/sample-applications.html#makefile3), and [opencv\_rotate.cpp](https://docs.qualcomm.com/doc/80-80022-21/topic/sample-applications.html#opencv-rotate-cpp3) files in the `/opencv_rotate/` directory. Note The JPG image referenced in this example is from [https://github.com/opencv/opencv_extra/blob/4.x/testdata/stitching/boat1.jpg](https://github.com/opencv/opencv_extra/blob/4.x/testdata/stitching/boat1.jpg), and can be changed. - `configure.ac` AC_PREREQ([2.71]) AC_INIT([opencv_rotate],[1.0.0]) AM_INIT_AUTOMAKE([-Wall gnu foreign subdir-objects]) AC_CONFIG_SRCDIR([Makefile.am]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) AC_ARG_WITH([sanitized-headers], [AS_HELP_STRING([--with-sanitized-headers=DIR],[location of the sanitized Linux headers])], [CPPFLAGS="$CPPFLAGS -I$withval"]) AM_PROG_AS AM_PROG_AR AC_PROG_CC AM_PROG_CC_C_O AC_PROG_CPP AC_PROG_CXX LT_INIT AC_PROG_AWK AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET AC_ARG_WITH([opencv-path], [AS_HELP_STRING([--with-opencv-path=DIR],[path to opencv])], [OPENCV_PATH="$withval"]) # The toolchain parameter passed by the bitbake is consumed here AC_ARG_WITH([toolchain-used], AS_HELP_STRING([--with-toolchain-used], [Specify the toolchain-used for compilation]), [toolchain_used=$withval], toolchain_used=sdllvm) AM_CONDITIONAL(GCC_ENABLE, test "x$toolchain_used" = "xgcc") AM_CONDITIONAL(SDLLVM_ENABLE, test "x$toolchain_used" = "xsdllvm") AC_SUBST([OPENCV_PATH]) AC_CONFIG_FILES([ Makefile]) AC_OUTPUT Copy to clipboard - `Makefile.am` #ACLOCAL_AMFLAGS = -I m4 # --------------------------------------------------------------------------------- # Make the libfastcvOPT library (libfastcvopt) # --------------------------------------------------------------------------------- common_flags = -O3 \ -fPIC \ -Wall \ -Wno-error \ -Wno-error=uninitialized \ -flax-vector-conversions \ -I${OPENCV_PATH} AM_CFLAGS = $(common_flags) AM_CPPFLAGS = $(common_flags) test_sources = opencv_rotate.cpp bin_PROGRAMS = opencv_rotate_test opencv_rotate_test_SOURCES = $(test_sources) opencv_rotate_test_CPPFLAGS = $(AM_CPPFLAGS) opencv_rotate_test_CFLAGS = $(AM_CFLAGS) opencv_rotate_test_LDADD = -ldl -lpthread -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_fastcv Copy to clipboard - `opencv_rotate.cpp` #include #include #include "opencv2/opencv.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/fastcv/scale.hpp" using namespace cv; int main() { Mat input = imread("/tmp/test/samples/boat1.jpg"); Mat dst; auto start = std::chrono::high_resolution_clock::now(); rotate(input, dst, ROTATE_90_CLOCKWISE); imwrite("/tmp/test/samples/output.jpg", dst); auto end = std::chrono::high_resolution_clock::now(); std::chrono::microseconds time_span = std::chrono::duration_cast(end - start); std::cout << "Total time taken: " << time_span.count() << " us.\n"; return 0; } Copy to clipboard ### Compile OpenCV rotate application 1. Run the following commands. mkdir -p m4 aclocal autoconf touch NEWS README AUTHORS ChangeLog autoreconf --install automake -a ./configure ${CONFIGURE_FLAGS} --with-opencv_path=${SDKTARGETSYSROOT}/armv8a-qcom-linux/usr/include/opencv4 Copy to clipboard 2. Run the `make` command to compile the application. make Copy to clipboard The `opencv_rotate_test` test application generates in the `/opencv_rotate/` directory. ### Run the OpenCV rotate application 1. To push the test bin, run the following command on the host. scp -r opencv_rotate_test root@{[IP-ADDR]}:/usr/bin/ Copy to clipboard Note If you are unable to copy the file, remount using the following commands: mount -o remount,rw /usr Copy to clipboard Check permissions using: mount | grep / Copy to clipboard 2. Run the following command to change directories (`cd`) to the path (for example `/images/boat1.jpg`) of the test image. cd {} Copy to clipboard 3. Create a directory (for example `/tmp/test/samples/`) on the device to push the test image. This `/tmp/test/samples/` directory is also the location of the output image in test code. Modify this directory according to the specified output location on your machine. 4. Run the following command to push the test image to the device. scp -r boat1.jpg root@{[IP-ADDR]}:{/tmp/test/samples/} Copy to clipboard 5. To start the test on the target device, run the following commands. chmod 777 /usr/bin/opencv_rotate_test /usr/bin/opencv_rotate_test Copy to clipboard 6. To get the results, run the following command. scp -r root@{[IP-ADDR]}:/tmp/test/samples/output.jpg user2@{[HOST IP-ADDR]}:/workspace Copy to clipboard The `/tmp/test/samples/` directory is the location of the output image in test code. Modify according to your specified output location. The following is the expected result. | Input | Rotate | Output | | --- | --- | --- | | | ROTATE\_90\_CLOCKWISE | | ## Implement OpenCV resize application with FastCV extension See [OpenCV resize()](https://docs.qualcomm.com/doc/80-80022-21/topic/sample-applications.html#opencv-resize) for API usage details. 1. Once the SDK is installed, run the following commands to create and change the `/opencv_resize_extension/` directory in the SDK install directory. mkdir opencv_resize_extension cd opencv_resize_extension Copy to clipboard 2. Create the following `configure.ac`, `Makefile.am`, and `opencv_resize_extension.cpp` files in the `/opencv_resize_extension/` directory. Note The PNG image referenced in this example is [https://github.com/opencv/opencv/blob/4.x/samples/data/box_in_scene.png](https://github.com/opencv/opencv/blob/4.x/samples/data/box_in_scene.png), but you can use another image if you want. - `configure.ac` AC_PREREQ([2.71]) AC_INIT([opencv_resize],[1.0.0]) AM_INIT_AUTOMAKE([-Wall gnu foreign subdir-objects]) AC_CONFIG_SRCDIR([Makefile.am]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) AC_ARG_WITH([sanitized-headers], [AS_HELP_STRING([--with-sanitized-headers=DIR],[location of the sanitized Linux headers])], [CPPFLAGS="$CPPFLAGS -I$withval"]) AM_PROG_AS AM_PROG_AR AC_PROG_CC AM_PROG_CC_C_O AC_PROG_CPP AC_PROG_CXX LT_INIT AC_PROG_AWK AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET AC_ARG_WITH([opencv-path], [AS_HELP_STRING([--with-opencv-path=DIR],[path to opencv])], [OPENCV_PATH="$withval"]) # The toolchain parameter passed by the bitbake is consumed here AC_ARG_WITH([toolchain-used], AS_HELP_STRING([--with-toolchain-used], [Specify the toolchain-used for compilation]), [toolchain_used=$withval], toolchain_used=sdllvm) AM_CONDITIONAL(GCC_ENABLE, test "x$toolchain_used" = "xgcc") AM_CONDITIONAL(SDLLVM_ENABLE, test "x$toolchain_used" = "xsdllvm") AC_SUBST([OPENCV_PATH]) AC_CONFIG_FILES([ Makefile]) AC_OUTPUT Copy to clipboard - `Makefile.am` #ACLOCAL_AMFLAGS = -I m4 # --------------------------------------------------------------------------------- # Make the libfastcvOPT library (libfastcvopt) # --------------------------------------------------------------------------------- common_flags = -O3 \ -fPIC \ -Wall \ -Wno-error \ -Wno-error=uninitialized \ -flax-vector-conversions \ -I${OPENCV_PATH} AM_CFLAGS = $(common_flags) AM_CPPFLAGS = $(common_flags) test_sources = opencv_resize_extension.cpp bin_PROGRAMS = opencv_resize_test opencv_resize_test_SOURCES = $(test_sources) opencv_resize_test_CPPFLAGS = $(AM_CPPFLAGS) opencv_resize_test_CFLAGS = $(AM_CFLAGS) opencv_resize_test_LDADD = -ldl -lpthread -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_fastcv Copy to clipboard - `opencv_resize_extension.cpp` #include #include #include "opencv2/opencv.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/fastcv/scale.hpp" using namespace cv; int main() { Mat input = imread("/tmp/test/samples/box_in_scene.png", IMREAD_GRAYSCALE); Mat dst ; auto start = std::chrono::high_resolution_clock::now(); fastcv::resizeDown(input, dst, cv::Size(), 0.5, 0.5); //resize(input, dst, Size(), 0.5, 0.5, INTER_LINEAR); imwrite("/tmp/test/samples/output.png", dst); auto end = std::chrono::high_resolution_clock::now(); std::chrono::microseconds time_span = std::chrono::duration_cast(end - start); std::cout << "Total time taken: " << time_span.count() << " us.\n"; // if(!dst) std::cout << "Test not executed properly" << std::endl; return 0; } Copy to clipboard ### Compile OpenCV resize application 1. Run the following commands. mkdir -p m4 aclocal autoconf touch NEWS README AUTHORS ChangeLog autoreconf --install automake -a ./configure ${CONFIGURE_FLAGS} --with-opencv_path=${SDKTARGETSYSROOT}/armv8a-qcom-linux/usr/include/opencv4 Copy to clipboard 2. Run the make command to compile the application. make Copy to clipboard The `opencv_resize_test` test application generates in the `/opencv_resize_extension/` directory. ### Run OpenCV resize application 1. To push the test bin, run the following command on the host. scp -r opencv_resize_test root@{[IP-ADDR]}:/usr/bin/ Copy to clipboard 2. Run the following command to change directories (`cd`) to the path of the test image (for example `/images/box_in_scene.png`). cd {} Copy to clipboard 3. Create a directory on the device to copy the test image to (for example `/tmp/test/samples/`). This `/tmp/test/samples/` directory is also the location of the output image in the sample code. Modify this directory according to the specified output location on your machine. 4. Run the following command to copy the test image to the device. scp -r box_in_scene.png root@{[IP-ADDR]}:{/tmp/test/samples/} Copy to clipboard 5. To start the test on the target device, run the following commands. chmod 777 /usr/bin/opencv_resize_test /usr/bin/opencv_resize_test Copy to clipboard 6. To get the results, run the following command. scp -r root@{[IP-ADDR]}:/tmp/test/samples/output.png user2@{[HOST IP-ADDR]}:/workspace Copy to clipboard The `/tmp/test/samples/` directory is the location of the output image in the sample code. Modify this location according to your specified output location. The following is the expected result. | Input | Resize factor | Output | | --- | --- | --- | | | fx=1/2 fy=1/2 | | ## OpenCV rotate function usage Rotates a 2D array in multiples of 90 degrees. The `rotate()` function rotates the array in one of the following ways. - 90 degrees clockwise: `rotateCode = ROTATE_90_CLOCKWISE` - 180 degrees clockwise: `rotateCode = ROTATE_180` - 270 degrees clockwise: `rotateCode = ROTATE_90_COUNTERCLOCKWISE` Parameters | Type | Parameter | Description | | --- | --- | --- | | InputArray | `src` | Input array. | | OutputArray | `dst` | Output array of the same type as the source.


The size is the same with `ROTATE_180` and the rows and columns are switched for `ROTATE_90_CLOCKWISE` and `ROTATE_90_COUNTERCLOCKWISE`. | | int | code | An enum to specify how to rotate the array; see the `RotateFlags` enum.


RotateFlags:

  • ROTATE_90_CLOCKWISE


  • ROTATE_180


  • ROTATE_90_COUNTERCLOCKWISE


| For more information about `rotate()`, see [the full API documentation](https://docs.opencv.org/3.4/d2/de8/group__core__array.html#ga4ad01c0978b0ce64baa246811deeac24) ## OpenCV resize function usage Input to the OpenCV resize() function is a source (src) image in the form of CVMatrix. Note Only grayscale images are supported. Output is a destination image in the form of CVMatrix. The FastCV namespace is used to call the FastCV extension APIs. The resizeDown() extension API requires the input image and destination image as parameters. Parameters | Type | Parameter | Description | | --- | --- | --- | | InputArray | input | Input image. | | OutputArray | dst | Output image. | | Size | dsize | The desired size of the output image. If empty, it is calculated using inv\_scale\_x and inv\_scale\_y. | | double | inv\_scale\_x | The inverse scaling factor for the width. If `dsize` is provided, this parameter is ignored. | | double | inv\_scale\_y | The inverse scaling factor for the height. If `dsize` is provided, this parameter is ignored. | For more information about `resize()`, see [the full API documentation](https://docs.opencv.org/4.13.0/da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d). Last Published: Jul 07, 2026 [Previous Topic Run existing test app](https://docs.qualcomm.com/bundle/publicresource/80-80022-21/topics/opencv-test-application.md) [Next Topic Evaluate fast CV acceleration](https://docs.qualcomm.com/bundle/publicresource/80-80022-21/topics/fastcv-acceleration.md)