Skip to main content

Implement and deploy OpenCV sample application

Developer workflow

Prerequisites

Implement OpenCV rotate application with FastCV

See 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:
  2. Run the following commands to create and change the opencv_rotate directory in the SDK install directory.
  3. Create the following configure.ac, Makefile.am and opencv_rotate.cpp files in the opencv_rotate directory.
    NoteThe JPG image referenced in this example is from https://github.com/opencv/opencv_extra/blob/4.x/testdata/stitching/boat1.jpg, and can be changed.
    • configure.ac
    • Makefile.am
    • opencv_rotate.cpp

Compile OpenCV rotate application

  1. Run the following commands.
  2. Run the make command to compile the application.
    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.
    NoteIf you are unable to copy the file, remount using the following commands:
    Check permissions using:
  2. Run the following command to change directories (cd) to the path (for example ./images/boat1.jpg) of the test image.
  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.
  5. To start the test on the target device, run the following commands.
  6. To get the results, run the following command.
    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.

Implement OpenCV resize application with FastCV extension

See 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.
  2. Create the following configure.ac, Makefile.am, and opencv_resize_extension.cpp files in the opencv_resize_extension directory.
    NoteThe PNG image referenced in this example is 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
    • Makefile.am
    • opencv_resize_extension.cpp

Compile OpenCV resize application

  1. Run the following commands.
  2. Run the make command to compile the application.
    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.
  2. Run the following command to change directories (cd) to the path of the test image (for example ./images/box_in_scene.png).
  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.
  5. To start the test on the target device, run the following commands.
  6. To get the results, run the following command.
    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.

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
TypeParameterDescription
InputArraysrcInput array.
OutputArraydstOutput 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.
intcodeAn 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

OpenCV resize function usage

Input to the OpenCV resize() function is a source (src) image in the form of CVMatrix.
NoteOnly 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
TypeParameterDescription
InputArrayinputInput image.
OutputArraydstOutput image.
SizedsizeThe desired size of the output image. If empty, it is calculated using inv_scale_x and inv_scale_y.
doubleinv_scale_xThe inverse scaling factor for the width. If dsize is provided, this parameter is ignored.
doubleinv_scale_yThe inverse scaling factor for the height. If dsize is provided, this parameter is ignored.
For more information about resize(), see the full API documentation.