Skip to content

Commit 5f1b05a

Browse files
authored
Merge pull request opencv#26556 from asmorkalov:FastcvHAL_1stPost
Added Fastcv HAL changes in the 3rdparty folder. Code Changes includes HAL code , Fastcv libs and Headers Change-Id: I2f0ddb1f57515c82ae86ba8c2a82965b1a9626ec Requires binaries from opencv/opencv_3rdparty#86. Related patch to opencv_contrib: opencv/opencv_contrib#3811 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
1 parent 96dab6b commit 5f1b05a

File tree

10 files changed

+1214
-0
lines changed

10 files changed

+1214
-0
lines changed

3rdparty/fastcv/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
if(HAVE_FASTCV)
2+
set(FASTCV_HAL_VERSION 0.0.1 CACHE INTERNAL "")
3+
set(FASTCV_HAL_LIBRARIES "fastcv_hal" CACHE INTERNAL "")
4+
set(FASTCV_HAL_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE INTERNAL "")
5+
set(FASTCV_HAL_HEADERS
6+
"${CMAKE_CURRENT_SOURCE_DIR}/include/fastcv_hal_core.hpp"
7+
"${CMAKE_CURRENT_SOURCE_DIR}/include/fastcv_hal_imgproc.hpp"
8+
CACHE INTERNAL "")
9+
10+
file(GLOB FASTCV_HAL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
11+
12+
add_library(fastcv_hal STATIC ${FASTCV_HAL_FILES})
13+
14+
target_include_directories(fastcv_hal PRIVATE
15+
${CMAKE_SOURCE_DIR}/modules/core/include
16+
${CMAKE_SOURCE_DIR}/modules/imgproc/include
17+
${FASTCV_HAL_INCLUDE_DIRS} ${FastCV_INCLUDE_PATH})
18+
19+
target_link_libraries(fastcv_hal PUBLIC ${FASTCV_LIBRARY})
20+
21+
set_target_properties(fastcv_hal PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH})
22+
23+
if(NOT BUILD_SHARED_LIBS)
24+
ocv_install_target(fastcv_hal EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
25+
endif()
26+
27+
ocv_install_3rdparty_licenses(FastCV "${OpenCV_BINARY_DIR}/3rdparty/fastcv/LICENSE")
28+
29+
if(ENABLE_SOLUTION_FOLDERS)
30+
set_target_properties(fastcv_hal PROPERTIES FOLDER "3rdparty")
31+
endif()
32+
else()
33+
message(STATUS "FastCV is not available, disabling related HAL")
34+
endif(HAVE_FASTCV)

3rdparty/fastcv/fastcv.cmake

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function(download_fastcv root_dir)
2+
3+
# Commit SHA in the opencv_3rdparty repo
4+
set(FASTCV_COMMIT "b8f0d48fa9dbebb0237d3e0abd206f9930c89db6")
5+
6+
# Define actual FastCV versions
7+
if(ANDROID)
8+
if(AARCH64)
9+
message(STATUS "Download FastCV for Android aarch64")
10+
set(FCV_PACKAGE_NAME "fastcv_android_aarch64_2024_10_24.tgz")
11+
set(FCV_PACKAGE_HASH "14486af00dc0282dac591dc9ccdd957e")
12+
else()
13+
message(STATUS "Download FastCV for Android armv7")
14+
set(FCV_PACKAGE_NAME "fastcv_android_arm32_2024_10_24.tgz")
15+
set(FCV_PACKAGE_HASH "b5afadd5a5b55f8f6c2e7361f225fa21")
16+
endif()
17+
elseif(UNIX AND NOT APPLE AND NOT IOS AND NOT XROS)
18+
if(AARCH64)
19+
set(FCV_PACKAGE_NAME "fastcv_linux_aarch64_2024_10_24.tgz")
20+
set(FCV_PACKAGE_HASH "d15c7b77f2d3577ba46bd94e6cf15230")
21+
else()
22+
message("FastCV: fastcv lib for 32-bit Linux is not supported for now!")
23+
endif()
24+
endif(ANDROID)
25+
26+
# Download Package
27+
set(OPENCV_FASTCV_URL "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${FASTCV_COMMIT}/fastcv/")
28+
29+
ocv_download( FILENAME ${FCV_PACKAGE_NAME}
30+
HASH ${FCV_PACKAGE_HASH}
31+
URL ${OPENCV_FASTCV_URL}
32+
DESTINATION_DIR ${root_dir}
33+
ID FASTCV
34+
STATUS res
35+
UNPACK
36+
RELATIVE_URL)
37+
if(res)
38+
set(HAVE_FASTCV TRUE CACHE BOOL "FastCV status")
39+
else()
40+
message(WARNING "FastCV: package download failed!")
41+
endif()
42+
43+
endfunction()
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OPENCV_FASTCV_HAL_CORE_HPP_INCLUDED
7+
#define OPENCV_FASTCV_HAL_CORE_HPP_INCLUDED
8+
9+
#include <opencv2/core/base.hpp>
10+
11+
#undef cv_hal_lut
12+
#define cv_hal_lut fastcv_hal_lut
13+
#undef cv_hal_normHammingDiff8u
14+
#define cv_hal_normHammingDiff8u fastcv_hal_normHammingDiff8u
15+
#undef cv_hal_mul8u16u
16+
#define cv_hal_mul8u16u fastcv_hal_mul8u16u
17+
#undef cv_hal_sub8u32f
18+
#define cv_hal_sub8u32f fastcv_hal_sub8u32f
19+
#undef cv_hal_transpose2d
20+
#define cv_hal_transpose2d fastcv_hal_transpose2d
21+
#undef cv_hal_meanStdDev
22+
#define cv_hal_meanStdDev fastcv_hal_meanStdDev
23+
#undef cv_hal_flip
24+
#define cv_hal_flip fastcv_hal_flip
25+
#undef cv_hal_rotate90
26+
#define cv_hal_rotate90 fastcv_hal_rotate
27+
28+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
29+
/// @brief look-up table transform of an array.
30+
/// @param src_data Source image data
31+
/// @param src_step Source image step
32+
/// @param src_type Source image type
33+
/// @param lut_data Pointer to lookup table
34+
/// @param lut_channel_size Size of each channel in bytes
35+
/// @param lut_channels Number of channels in lookup table
36+
/// @param dst_data Destination data
37+
/// @param dst_step Destination step
38+
/// @param width Width of images
39+
/// @param height Height of images
40+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41+
int fastcv_hal_lut(
42+
const uchar* src_data,
43+
size_t src_step,
44+
size_t src_type,
45+
const uchar* lut_data,
46+
size_t lut_channel_size,
47+
size_t lut_channels,
48+
uchar* dst_data,
49+
size_t dst_step,
50+
int width,
51+
int height);
52+
53+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54+
/// @brief Hamming distance between two vectors
55+
/// @param a pointer to first vector data
56+
/// @param b pointer to second vector data
57+
/// @param n length of vectors
58+
/// @param cellSize how many bits of the vectors will be added and treated as a single bit, can be 1 (standard Hamming distance), 2 or 4
59+
/// @param result pointer to result output
60+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61+
int fastcv_hal_normHammingDiff8u(const uchar* a, const uchar* b, int n, int cellSize, int* result);
62+
63+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64+
int fastcv_hal_mul8u16u(
65+
const uchar * src1_data,
66+
size_t src1_step,
67+
const uchar * src2_data,
68+
size_t src2_step,
69+
ushort * dst_data,
70+
size_t dst_step,
71+
int width,
72+
int height,
73+
double scale);
74+
75+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76+
int fastcv_hal_sub8u32f(
77+
const uchar *src1_data,
78+
size_t src1_step,
79+
const uchar *src2_data,
80+
size_t src2_step,
81+
float *dst_data,
82+
size_t dst_step,
83+
int width,
84+
int height);
85+
86+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87+
int fastcv_hal_transpose2d(
88+
const uchar* src_data,
89+
size_t src_step,
90+
uchar* dst_data,
91+
size_t dst_step,
92+
int src_width,
93+
int src_height,
94+
int element_size);
95+
96+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
97+
int fastcv_hal_meanStdDev(
98+
const uchar * src_data,
99+
size_t src_step,
100+
int width,
101+
int height,
102+
int src_type,
103+
double * mean_val,
104+
double * stddev_val,
105+
uchar * mask,
106+
size_t mask_step);
107+
108+
109+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110+
/// @brief Flips a 2D array around vertical, horizontal, or both axes
111+
/// @param src_type source and destination image type
112+
/// @param src_data source image data
113+
/// @param src_step source image step
114+
/// @param src_width source and destination image width
115+
/// @param src_height source and destination image height
116+
/// @param dst_data destination image data
117+
/// @param dst_step destination image step
118+
/// @param flip_mode 0 flips around x-axis, 1 around y-axis, -1 both
119+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120+
int fastcv_hal_flip(
121+
int src_type,
122+
const uchar* src_data,
123+
size_t src_step,
124+
int src_width,
125+
int src_height,
126+
uchar* dst_data,
127+
size_t dst_step,
128+
int flip_mode);
129+
130+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
131+
/// @brief Rotates a 2D array in multiples of 90 degrees.
132+
/// @param src_type source and destination image type
133+
/// @param src_data source image data
134+
/// @param src_step source image step
135+
/// @param src_width source image width
136+
/// @If angle has value [180] it is also destination image width
137+
/// If angle has values [90, 270] it is also destination image height
138+
/// @param src_height source and destination image height (destination image width for angles [90, 270])
139+
/// If angle has value [180] it is also destination image height
140+
/// If angle has values [90, 270] it is also destination image width
141+
/// @param dst_data destination image data
142+
/// @param dst_step destination image step
143+
/// @param angle clockwise angle for rotation in degrees from set [90, 180, 270]
144+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
145+
int fastcv_hal_rotate(
146+
int src_type,
147+
const uchar* src_data,
148+
size_t src_step,
149+
int src_width,
150+
int src_height,
151+
uchar* dst_data,
152+
size_t dst_step,
153+
int angle);
154+
155+
#endif
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OPENCV_FASTCV_HAL_IMGPROC_HPP_INCLUDED
7+
#define OPENCV_FASTCV_HAL_IMGPROC_HPP_INCLUDED
8+
9+
#include <opencv2/core/base.hpp>
10+
11+
#undef cv_hal_medianBlur
12+
#define cv_hal_medianBlur fastcv_hal_medianBlur
13+
#undef cv_hal_sobel
14+
#define cv_hal_sobel fastcv_hal_sobel
15+
#undef cv_hal_boxFilter
16+
#define cv_hal_boxFilter fastcv_hal_boxFilter
17+
#undef cv_hal_adaptiveThreshold
18+
#define cv_hal_adaptiveThreshold fastcv_hal_adaptiveThreshold
19+
20+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
21+
/// @brief Calculate medianBlur filter
22+
/// @param src_data Source image data
23+
/// @param src_step Source image step
24+
/// @param dst_data Destination image data
25+
/// @param dst_step Destination image step
26+
/// @param width Source image width
27+
/// @param height Source image height
28+
/// @param depth Depths of source and destination image
29+
/// @param cn Number of channels
30+
/// @param ksize Size of kernel
31+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32+
int fastcv_hal_medianBlur(
33+
const uchar* src_data,
34+
size_t src_step,
35+
uchar* dst_data,
36+
size_t dst_step,
37+
int width,
38+
int height,
39+
int depth,
40+
int cn,
41+
int ksize);
42+
43+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44+
/// @brief Computes Sobel derivatives
45+
///
46+
/// @param src_data Source image data
47+
/// @param src_step Source image step
48+
/// @param dst_data Destination image data
49+
/// @param dst_step Destination image step
50+
/// @param width Source image width
51+
/// @param height Source image height
52+
/// @param src_depth Depth of source image
53+
/// @param dst_depth Depths of destination image
54+
/// @param cn Number of channels
55+
/// @param margin_left Left margins for source image
56+
/// @param margin_top Top margins for source image
57+
/// @param margin_right Right margins for source image
58+
/// @param margin_bottom Bottom margins for source image
59+
/// @param dx orders of the derivative x
60+
/// @param dy orders of the derivative y
61+
/// @param ksize Size of kernel
62+
/// @param scale Scale factor for the computed derivative values
63+
/// @param delta Delta value that is added to the results prior to storing them in dst
64+
/// @param border_type Border type
65+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66+
int fastcv_hal_sobel(
67+
const uchar* src_data,
68+
size_t src_step,
69+
uchar* dst_data,
70+
size_t dst_step,
71+
int width,
72+
int height,
73+
int src_depth,
74+
int dst_depth,
75+
int cn,
76+
int margin_left,
77+
int margin_top,
78+
int margin_right,
79+
int margin_bottom,
80+
int dx,
81+
int dy,
82+
int ksize,
83+
double scale,
84+
double delta,
85+
int border_type);
86+
87+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88+
/// @brief Canny edge detector
89+
/// @param src_data Source image data
90+
/// @param src_step Source image step
91+
/// @param dst_data Destination image data
92+
/// @param dst_step Destination image step
93+
/// @param width Source image width
94+
/// @param height Source image height
95+
/// @param cn Number of channels
96+
/// @param lowThreshold low thresholds value
97+
/// @param highThreshold high thresholds value
98+
/// @param ksize Kernel size for Sobel operator.
99+
/// @param L2gradient Flag, indicating use L2 or L1 norma.
100+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101+
int fastcv_hal_canny(
102+
const uchar* src_data,
103+
size_t src_step,
104+
uchar* dst_data,
105+
size_t dst_step,
106+
int width,
107+
int height,
108+
int cn,
109+
double lowThreshold,
110+
double highThreshold,
111+
int ksize,
112+
bool L2gradient);
113+
114+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115+
116+
int fastcv_hal_boxFilter(
117+
const uchar* src_data,
118+
size_t src_step,
119+
uchar* dst_data,
120+
size_t dst_step,
121+
int width,
122+
int height,
123+
int src_depth,
124+
int dst_depth,
125+
int cn,
126+
int margin_left,
127+
int margin_top,
128+
int margin_right,
129+
int margin_bottom,
130+
size_t ksize_width,
131+
size_t ksize_height,
132+
int anchor_x,
133+
int anchor_y,
134+
bool normalize,
135+
int border_type);
136+
137+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
138+
int fastcv_hal_adaptiveThreshold(
139+
const uchar* src_data,
140+
size_t src_step,
141+
uchar* dst_data,
142+
size_t dst_step,
143+
int width,
144+
int height,
145+
double maxValue,
146+
int adaptiveMethod,
147+
int thresholdType,
148+
int blockSize,
149+
double C);
150+
151+
#endif

0 commit comments

Comments
 (0)