-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
base: 4.x
Are you sure you want to change the base?
Changes from all commits
ca11f8f
b8b5757
ddaff0f
25a572f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
if((ARM OR AARCH64) AND (ANDROID OR (UNIX AND NOT APPLE AND NOT IOS AND NOT XROS))) | ||
set(the_description "FastCV extension module") | ||
set(FCV_MODULE_HEADER_DIR "${CMAKE_CURRENT_BINARY_DIR}/inc") | ||
set(FCV_MODULE_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/libs") | ||
|
||
# here you can change the library to a specific one | ||
set(FASTCV_LIB "${FCV_MODULE_LIB_DIR}/libfastcvopt.so") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line |
||
if((NOT EXISTS ${FCV_MODULE_HEADER_DIR}) OR (NOT EXISTS ${FCV_MODULE_LIB_DIR})) | ||
include("${CMAKE_CURRENT_SOURCE_DIR}/fastcv.cmake") | ||
download_fastcv("${CMAKE_CURRENT_BINARY_DIR}") | ||
endif() | ||
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let it be called from the root cmake in main repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have this cmake/OpenCVFindFastCV.cmake for the HAL in the main repo, this part is for extension, they are downloading to different folders |
||
|
||
ocv_define_module(fastcv opencv_core opencv_imgproc opencv_features2d opencv_video WRAP python java) | ||
ocv_module_include_directories( | ||
"${CMAKE_CURRENT_SOURCE_DIR}/include" | ||
${FCV_MODULE_HEADER_DIR}) | ||
ocv_target_link_libraries(${the_module} ${FASTCV_LIB}) | ||
ocv_target_compile_definitions(${the_module} PRIVATE FAST_CV_FOUND) | ||
else() | ||
message(FATAL_ERROR "FastCV supports ARM Platform on Android and Linux only!") | ||
endif() |
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or have implementation incompatible with OpenCV. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior was changed, please change this part of readme. |
||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function(download_fastcv root_dir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be in main CMake. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are already on in the main repo, will try to reuse that one |
||
|
||
# Commit SHA in the opencv_3rdparty repo | ||
set(FASTCV_COMMIT "65f40fc8f7a6aac44936ae9538e69edede6c4b15") | ||
|
||
# Define actual FCV versions | ||
if(ANDROID) | ||
if(AARCH64) | ||
set(FCV_PACKAGE_NAME "fastcv_android_aarch64_2024_10_24.tgz") | ||
set(FCV_PACKAGE_HASH "8a259eea80064643bad20f72ba0b6066") | ||
else() | ||
set(FCV_PACKAGE_NAME "fastcv_android_arm32_2024_10_24.tgz") | ||
set(FCV_PACKAGE_HASH "04d89219c44d54166b2b7f8c0ed5143b") | ||
endif() | ||
elseif(UNIX AND NOT APPLE AND NOT IOS AND NOT XROS) | ||
message("FastCV: fastcv lib for Linux is not supported for now!") | ||
endif(ANDROID) | ||
|
||
# Download Package | ||
set(OPENCV_FASTCV_URL "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${FASTCV_COMMIT}/fastcv/") | ||
|
||
ocv_download( FILENAME ${FCV_PACKAGE_NAME} | ||
HASH ${FCV_PACKAGE_HASH} | ||
URL ${OPENCV_FASTCV_URL} | ||
DESTINATION_DIR ${root_dir} | ||
ID FASTCV | ||
STATUS res | ||
UNPACK | ||
RELATIVE_URL) | ||
|
||
if(NOT res) | ||
message("FastCV: package download failed! Please download FastCV manually and put it at ${root_dir}.") | ||
endif() | ||
|
||
endfunction() |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
//! @} | ||
|
||
} // fastcv:: | ||
} // cv:: | ||
|
||
#endif // OPENCV_FASTCV_ARITHM_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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be checked in the code with something like |
||
|
||
* @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 |
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 |
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 |
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is the same code in main repo. I propose to remove duplicates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we download the headers and libs to different folders in case someone build the opencv_contrib without enabling WITH_FASTCV flag