Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastCV Extension code for Opencv APIs #3811

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions modules/fastcv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(the_description "FastCV extension module")
ocv_define_module(fastcv opencv_core opencv_imgproc opencv_features2d opencv_video WRAP python java)

if (FASTCV_DIR)
if(NOT ARM AND NOT AARCH64)
# the reason this warning is not fatal is to enable proper code analysis
# in your favourite IDE
message(WARNING "FastCV supports ARM platform only!")
endif()

# here you can change the library to a specific one
set(FASTCV_LIB "/libs/Android/lib64/libfastcvopt.so")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line


ocv_module_include_directories("${FASTCV_DIR}/inc")
ocv_target_link_libraries(${the_module} LINK_PRIVATE "${FASTCV_DIR}/${FASTCV_LIB}")
ocv_target_compile_definitions(${the_module} PRIVATE FAST_CV_FOUND)
endif()
7 changes: 7 additions & 0 deletions modules/fastcv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FastCV extension for OpenCV
===========================

This module provides wrappers for several FastCV functions not covered by the corresponding HAL in OpenCV.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or have implementation incompatible with OpenCV.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add

Please note that:
1. This module supports ARM architecture only. This means that CMake script aborts configuration under x86 platform even if you don't want to build binaries for your machine and just want to build docs or enable code analysis in your IDE. In that case you should fix CMakeLists.txt file as told inside it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior was changed, please change this part of readme.
Now CMake will just emit a warning if the platform is not ARM but won't stop configuration. Any attempts to link under any platform but ARM would lead to a failure. The reason is to let various IDEs run their code analysis tools that require the code to be compiled at least.

2. Test data is stored in misc folder. Before running tests on a device you should copy the content of `misc/` folder to `$YOUR_TESTDATA_PATH/fastcv/` folder on a device.
34 changes: 34 additions & 0 deletions modules/fastcv/include/opencv2/arithm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OPENCV_FASTCV_ARITHM_HPP
#define OPENCV_FASTCV_ARITHM_HPP

#include <opencv2/core.hpp>

namespace cv {
namespace fastcv {

/**
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
*/

//! @addtogroup fastcv
//! @{

/**
* @brief Matrix multiplication of two int8_t type matrices

* @param src1 First source matrix of type CV_8S
* @param src2 Second source matrix of type CV_8S
* @param dst Resulting matrix of type CV_32S
*/
CV_EXPORTS_W void matmuls8s32(InputArray src1, _InputArray src2, OutputArray dst);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_InputArray src2 -> InputArray src2

//! @}

} // fastcv::
} // cv::

#endif // OPENCV_FASTCV_ARITHM_HPP
45 changes: 45 additions & 0 deletions modules/fastcv/include/opencv2/bilateralFilter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OPENCV_FASTCV_BILATERALFILTER_HPP
#define OPENCV_FASTCV_BILATERALFILTER_HPP

#include <opencv2/core.hpp>

namespace cv {
namespace fastcv {

/**
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
*/

//! @addtogroup fastcv
//! @{

/**
* @brief Applies Bilateral filter to an image considering d-pixel diameter of each pixel's neighborhood.
This filter does not work inplace.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be checked in the code with something like CV_Assert(src.data != dst.data);


* @param _src Intput image with type CV_8UC1
* @param _dst Destination image with same type as _src
* @param d kernel size (can be 5, 7 or 9)
* @param sigmaColor Filter sigma in the color space.
Typical value is 50.0f.
Increasing this value means increasing the influence of the neighboring pixels of more different color to the smoothing result.
* @param sigmaSpace Filter sigma in the coordinate space.
Typical value is 1.0f.
Increasing this value means increasing the influence of farther neighboring pixels within the kernel size distance to the smoothing result.
* @param borderType border mode used to extrapolate pixels outside of the image
*/
CV_EXPORTS_W void bilateralFilter( InputArray _src, OutputArray _dst, int d,
float sigmaColor, float sigmaSpace,
int borderType = BORDER_DEFAULT );

//! @}

} // fastcv::
} // cv::

#endif // OPENCV_FASTCV_BILATERALFILTER_HPP
46 changes: 46 additions & 0 deletions modules/fastcv/include/opencv2/cluster.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OPENCV_FASTCV_CLUSTER_HPP
#define OPENCV_FASTCV_CLUSTER_HPP

#include <opencv2/core.hpp>

namespace cv {
namespace fastcv {

/**
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
*/

//! @addtogroup fastcv
//! @{

/**
* @brief Clusterizes N input points in D-dimensional space into K clusters
*
* @param points Points array of type 8u, each row represets a point.
* Size is N rows by D columns, can be non-continuous.
* @param clusterCenters Initial cluster centers array of type 32f, each row represents a center.
* Size is K rows by D columns, can be non-continuous.
* @param newClusterCenters Resulting cluster centers array of type 32f, each row represents found center.
* Size is set to be K rows by D columns.
* @param clusterSizes Resulting cluster member counts array of type uint32, size is set to be 1 row by K columns.
* @param clusterBindings Resulting points indices array of type uint32, each index tells to which cluster the corresponding point belongs to.
* Size is set to be 1 row by numPointsUsed columns.
* @param clusterSumDists Resulting distance sums array of type 32f, each number is a sum of distances between each cluster center to its belonging points.
* Size is set to be 1 row by K columns
* @param numPointsUsed Number of points to clusterize starting from 0 to numPointsUsed-1 inclusively. Sets to N if negative.
*/
CV_EXPORTS_W void clusterEuclidean(InputArray points, InputArray clusterCenters, OutputArray newClusterCenters,
OutputArray clusterSizes, OutputArray clusterBindings, OutputArray clusterSumDists,
int numPointsUsed = -1);

//! @}

} // fastcv::
} // cv::

#endif // OPENCV_FASTCV_CLUSTER_HPP
36 changes: 36 additions & 0 deletions modules/fastcv/include/opencv2/draw.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OPENCV_FASTCV_DRAW_HPP
#define OPENCV_FASTCV_DRAW_HPP

#include <opencv2/core.hpp>

namespace cv {
namespace fastcv {

/**
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
*/

//! @addtogroup fastcv
//! @{

/**
* @brief Draw convex polygon
This function fills the interior of a convex polygon with the specified color.

* @param img Image to draw on. Should have up to 4 8-bit channels
* @param pts Array of polygon points coordinates. Should contain N two-channel or 2*N one-channel 32-bit integer elements
* @param color Color of drawn polygon stored as B,G,R and A(if supported)
*/
CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray pts, Scalar color);

//! @}

} // fastcv::
} // cv::

#endif // OPENCV_FASTCV_DRAW_HPP
46 changes: 46 additions & 0 deletions modules/fastcv/include/opencv2/fast10.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OPENCV_FASTCV_FAST10_HPP
#define OPENCV_FASTCV_FAST10_HPP

#include <opencv2/core.hpp>

namespace cv {
namespace fastcv {

/**
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
*/

//! @addtogroup fastcv
//! @{

/**
* @brief Extracts FAST corners and scores from the image based on the mask.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to highlight principal difference with OpenCV implementation. It's not obvious from the description.

The mask specifies pixels to be ignored by the detector

* @param src 8-bit grayscale image
* @param mask Optional mask indicating which pixels should be omited from corner dection.
Its size should be k times image width and height, where k = 1/2, 1/4 , 1/8 , 1, 2, 4 and 8
For more details see documentation to `fcvCornerFast9InMaskScoreu8` function in FastCV
* @param coords Output array of CV_32S containing interleave x, y positions of detected corners
* @param scores Optional output array containing the scores of the detected corners.
The score is the highest threshold that can still validate the detected corner.
A higher score value indicates a stronger corner feature.
For example, a corner of score 108 is stronger than a corner of score 50
* @param barrier FAST threshold. The threshold is used to compare difference between intensity value
of the central pixel and pixels on a circle surrounding this pixel
* @param border Number for pixels to ignore from top,bottom,right,left of the image. Defaults to 4 if it's below 4
* @param nmsEnabled Enable non-maximum suppresion to prune weak key points
*/
CV_EXPORTS_W void FAST10(InputArray src, InputArray mask, OutputArray coords, OutputArray scores, int barrier, int border, bool nmsEnabled);

//! @}

} // fastcv::
} // cv::

#endif // OPENCV_FASTCV_FAST10_HPP
51 changes: 51 additions & 0 deletions modules/fastcv/include/opencv2/fft.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OPENCV_FASTCV_FFT_HPP
#define OPENCV_FASTCV_FFT_HPP

#include <opencv2/core.hpp>

namespace cv {
namespace fastcv {

/**
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
*/

//! @addtogroup fastcv
//! @{

/**
* @brief Computes the 1D or 2D Fast Fourier Transform of a real valued matrix.
For the 2D case, the width and height of the input and output matrix must be powers of 2.
For the 1D case, the height of the matrices must be 1, while the width must be a power of 2.

* @param src Input array of CV_8UC1. The dimensions of the matrix must be powers of 2 for the 2D case,
and in the 1D case, the height must be 1, while the width must be a power of 2.
* @param dst The computed FFT matrix of type CV_32FC2. The FFT Re and Im coefficients are stored in different channels.
Hence the dimensions of the dst are (srcWidth, srcHeight)
*/
CV_EXPORTS_W void FFT(InputArray src, OutputArray dst);

/**
* @brief Computes the 1D or 2D Inverse Fast Fourier Transform of a complex valued matrix.
For the 2D case, The width and height of the input and output matrix must be powers of 2.
For the 1D case, the height of the matrices must be 1, while the width must be a power of 2.

* @param src Input array of type CV_32FC2 containing FFT Re and Im coefficients stored in separate channels.
The dimensions of the matrix must be powers of 2 for the 2D case, and in the 1D case, the height must be 1,
while the width must be a power of 2.
* @param dst The computed IFFT matrix of type CV_8U. The matrix is real valued and has no imaginary components.
Hence the dimensions of the dst are (srcWidth , srcHeight)
*/
CV_EXPORTS_W void IFFT(InputArray src, OutputArray dst);

//! @}

} // fastcv::
} // cv::

#endif // OPENCV_FASTCV_FFT_HPP
37 changes: 37 additions & 0 deletions modules/fastcv/include/opencv2/hough.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OPENCV_FASTCV_HOUGH_HPP
#define OPENCV_FASTCV_HOUGH_HPP

#include <opencv2/core.hpp>

namespace cv {
namespace fastcv {

/**
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
*/

//! @addtogroup fastcv
//! @{

/**
* @brief Performs Hough Line detection
*
* @param src Input 8-bit image containing binary contour. Width and step should be divisible by 8
* @param lines Output array containing detected lines in a form of (x1, y1, x2, y2) where all numbers are 32-bit floats
* @param threshold Controls the minimal length of a detected line. Value must be between 0.0 and 1.0
* Values close to 1.0 reduces the number of detected lines. Values close to 0.0
* detect more lines, but may be noisy. Recommended value is 0.25.
*/
CV_EXPORTS_W void houghLines(InputArray src, OutputArray lines, double threshold = 0.25);

//! @}

} // fastcv::
} // cv::

#endif // OPENCV_FASTCV_HOUGH_HPP
34 changes: 34 additions & 0 deletions modules/fastcv/include/opencv2/moments.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OPENCV_FASTCV_MOMENTS_HPP
#define OPENCV_FASTCV_MOMENTS_HPP

#include <opencv2/core.hpp>

namespace cv {
namespace fastcv {

/**
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
*/

//! @addtogroup fastcv
//! @{

/**
* @brief Calculates all of the moments up to the third order of the image pixels' intensities
The results are returned in the structure cv::Moments.
* @param _src Input image with type CV_8UC1, CV_32SC1, CV_32FC1
* @param binary If 1, binary image (0x00-black, oxff-white); if 0, grayscale image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> If true, assumes the image to be binary (0x00 for black, 0xff for white), otherwise assumes the image to be grayscale

*/
CV_EXPORTS_W cv::Moments moments(InputArray _src, bool binary);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moments are part of HAL and already wrapped, right?


//! @}

} // fastcv::
} // cv::

#endif // OPENCV_FASTCV_MOMENTS_HPP
Loading
Loading