Skip to content

Commit 2bc4fd0

Browse files
committed
Merge branch 4.x
2 parents bdbbcaa + 1e4d4e0 commit 2bc4fd0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2454
-191
lines changed

modules/fastcv/include/opencv2/fastcv.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#include "opencv2/fastcv/thresh.hpp"
3131
#include "opencv2/fastcv/tracking.hpp"
3232
#include "opencv2/fastcv/warp.hpp"
33+
#include "opencv2/fastcv/allocator.hpp"
34+
#include "opencv2/fastcv/dsp_init.hpp"
35+
#include "opencv2/fastcv/sad_dsp.hpp"
36+
#include "opencv2/fastcv/thresh_dsp.hpp"
37+
#include "opencv2/fastcv/fft_dsp.hpp"
38+
#include "opencv2/fastcv/edges_dsp.hpp"
39+
#include "opencv2/fastcv/blur_dsp.hpp"
3340

3441
/**
3542
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OPENCV_FASTCV_ALLOCATOR_HPP
7+
#define OPENCV_FASTCV_ALLOCATOR_HPP
8+
9+
#include <opencv2/core.hpp>
10+
#include <set>
11+
#include <mutex>
12+
13+
namespace cv {
14+
namespace fastcv {
15+
16+
//! @addtogroup fastcv
17+
//! @{
18+
19+
/**
20+
* @brief Resource manager for FastCV allocations.
21+
* This class manages active allocations.
22+
*/
23+
class QcResourceManager {
24+
public:
25+
static QcResourceManager& getInstance();
26+
27+
void addAllocation(void* ptr);
28+
void removeAllocation(void* ptr);
29+
30+
private:
31+
QcResourceManager() = default;
32+
std::set<void*> activeAllocations;
33+
std::mutex resourceMutex;
34+
};
35+
36+
/**
37+
* @brief Qualcomm's custom allocator.
38+
* This allocator uses Qualcomm's memory management functions.
39+
*/
40+
class QcAllocator : public cv::MatAllocator {
41+
public:
42+
QcAllocator();
43+
~QcAllocator();
44+
45+
cv::UMatData* allocate(int dims, const int* sizes, int type, void* data0, size_t* step, cv::AccessFlag flags, cv::UMatUsageFlags usageFlags) const CV_OVERRIDE;
46+
bool allocate(cv::UMatData* u, cv::AccessFlag accessFlags, cv::UMatUsageFlags usageFlags) const CV_OVERRIDE;
47+
void deallocate(cv::UMatData* u) const CV_OVERRIDE;
48+
};
49+
50+
/**
51+
* @brief Gets the default Qualcomm's allocator.
52+
* This function returns a pointer to the default Qualcomm's allocator, which is optimized
53+
* for use with DSP.
54+
*
55+
* @return Pointer to the default FastCV allocator.
56+
*/
57+
CV_EXPORTS cv::MatAllocator* getQcAllocator();
58+
59+
//! @}
60+
61+
} // namespace fastcv
62+
} // namespace cv
63+
64+
#endif // OPENCV_FASTCV_ALLOCATOR_HPP
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OPENCV_FASTCV_BLUR_DSP_HPP
7+
#define OPENCV_FASTCV_BLUR_DSP_HPP
8+
9+
#include <opencv2/core.hpp>
10+
11+
namespace cv {
12+
namespace fastcv {
13+
namespace dsp {
14+
15+
//! @addtogroup fastcv
16+
//! @{
17+
18+
/**
19+
* @brief Filter an image with non-separable kernel
20+
* @param _src Intput image with type CV_8UC1, src size should be greater than 176*144
21+
* @param _dst Output image with type CV_8UC1, CV_16SC1 or CV_32FC1
22+
* @param ddepth The depth of output image
23+
* @param _kernel Filer kernel data
24+
*/
25+
CV_EXPORTS void filter2D(InputArray _src, OutputArray _dst, int ddepth, InputArray _kernel);
26+
27+
//! @}
28+
29+
} // dsp::
30+
} // fastcv::
31+
} // cv::
32+
33+
#endif // OPENCV_FASTCV_BLUR_DSP_HPP
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OPENCV_FASTCV_DSP_INIT_HPP
7+
#define OPENCV_FASTCV_DSP_INIT_HPP
8+
9+
#include <opencv2/core.hpp>
10+
11+
namespace cv {
12+
namespace fastcv {
13+
namespace dsp {
14+
15+
//! @addtogroup fastcv
16+
//! @{
17+
18+
/**
19+
* @brief Initializes the FastCV DSP environment.
20+
*
21+
* This function sets up the necessary environment and resources for the DSP to operate.
22+
* It must be called once at the very beginning of the use case or program to ensure that
23+
* the DSP is properly initialized before any DSP-related operations are performed.
24+
*
25+
* @note This function must be called at the start of the use case or program, before any
26+
* DSP-related operations.
27+
*
28+
* @return int Returns 0 on success, and a non-zero value on failure.
29+
*/
30+
CV_EXPORTS int fcvdspinit();
31+
32+
/**
33+
* @brief Deinitializes the FastCV DSP environment.
34+
*
35+
* This function releases the resources and environment set up by the 'fcvdspinit' function.
36+
* It should be called before the use case or program exits to ensure that all DSP resources
37+
* are properly cleaned up and no memory leaks occur.
38+
*
39+
* @note This function must be called at the end of the use case or program, after all DSP-related
40+
* operations are complete.
41+
*/
42+
CV_EXPORTS void fcvdspdeinit();
43+
//! @}
44+
45+
} // dsp::
46+
} // fastcv::
47+
} // cv::
48+
49+
#endif // OPENCV_FASTCV_DSP_INIT_HPP
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OPENCV_FASTCV_EDGES_DSP_HPP
7+
#define OPENCV_FASTCV_EDGES_DSP_HPP
8+
9+
#include "opencv2/core/mat.hpp"
10+
11+
namespace cv {
12+
namespace fastcv {
13+
namespace dsp {
14+
15+
/**
16+
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
17+
*/
18+
19+
//! @addtogroup fastcv
20+
//! @{
21+
22+
/**
23+
* @brief Canny edge detector applied to a 8 bit grayscale image
24+
* @param _src Input image with type CV_8UC1
25+
* @param _dst Output 8-bit image containing the edge detection results
26+
* @param lowThreshold First threshold
27+
* @param highThreshold Second threshold
28+
* @param apertureSize The Sobel kernel size for calculating gradient. Supported sizes are 3, 5 and 7.
29+
* @param L2gradient L2 Gradient or L1 Gradient
30+
*/
31+
CV_EXPORTS void Canny(InputArray _src, OutputArray _dst, int lowThreshold, int highThreshold, int apertureSize = 3, bool L2gradient = false);
32+
//! @}
33+
34+
} // dsp::
35+
} // fastcv::
36+
} // cv::
37+
38+
#endif //OPENCV_FASTCV_EDGES_DSP_HPP
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OPENCV_FASTCV_FFT_DSP_HPP
7+
#define OPENCV_FASTCV_FFT_DSP_HPP
8+
9+
#include <opencv2/core.hpp>
10+
11+
namespace cv {
12+
namespace fastcv {
13+
namespace dsp {
14+
15+
//! @addtogroup fastcv
16+
//! @{
17+
18+
/**
19+
* @brief Computes the 1D or 2D Fast Fourier Transform of a real valued matrix.
20+
For the 2D case, the width and height of the input and output matrix must be powers of 2.
21+
For the 1D case, the height of the matrices must be 1, while the width must be a power of 2.
22+
23+
* @param src Input array of CV_8UC1. The dimensions of the matrix must be powers of 2 for the 2D case,
24+
and in the 1D case, the height must be 1, while the width must be a power of 2.
25+
* @param dst The computed FFT matrix of type CV_32FC2. The FFT Re and Im coefficients are stored in different channels.
26+
Hence the dimensions of the dst are (srcWidth, srcHeight)
27+
*/
28+
CV_EXPORTS void FFT(InputArray src, OutputArray dst);
29+
30+
/**
31+
* @brief Computes the 1D or 2D Inverse Fast Fourier Transform of a complex valued matrix.
32+
For the 2D case, The width and height of the input and output matrix must be powers of 2.
33+
For the 1D case, the height of the matrices must be 1, while the width must be a power of 2.
34+
35+
* @param src Input array of type CV_32FC2 containing FFT Re and Im coefficients stored in separate channels.
36+
The dimensions of the matrix must be powers of 2 for the 2D case, and in the 1D case, the height must be 1,
37+
while the width must be a power of 2.
38+
* @param dst The computed IFFT matrix of type CV_8U. The matrix is real valued and has no imaginary components.
39+
Hence the dimensions of the dst are (srcWidth , srcHeight)
40+
*/
41+
CV_EXPORTS void IFFT(InputArray src, OutputArray dst);
42+
43+
//! @}
44+
45+
} // dsp::
46+
} // fastcv::
47+
} // cv::
48+
49+
#endif // OPENCV_FASTCV_FFT_DSP_HPP
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OPENCV_FASTCV_SAD_HPP
7+
#define OPENCV_FASTCV_SAD_HPP
8+
9+
#include <opencv2/core.hpp>
10+
11+
namespace cv {
12+
namespace fastcv {
13+
namespace dsp {
14+
15+
/**
16+
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions
17+
*/
18+
19+
//! @addtogroup fastcv
20+
//! @{
21+
/**
22+
* @brief Sum of absolute differences of an image against an 8x8 template.
23+
* @param _patch The first input image data, type CV_8UC1
24+
* @param _src The input image data, type CV_8UC1
25+
* @param _dst The output image data, type CV_16UC1
26+
*/
27+
CV_EXPORTS void sumOfAbsoluteDiffs(cv::InputArray _patch, cv::InputArray _src, cv::OutputArray _dst);
28+
//! @}
29+
30+
} // dsp::
31+
} // fastcv::
32+
} // cv::
33+
34+
#endif // OPENCV_FASTCV_SAD_HPP

modules/fastcv/include/opencv2/fastcv/scale.hpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
2+
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -15,20 +15,18 @@ namespace fastcv {
1515
//! @{
1616

1717
/**
18-
* @brief Down-scale the image by averaging each 2x2 pixel block.
19-
* This function is not bit-exact with cv::resize but provides faster execution time on Qualcomm's processor.
20-
* @param _src The first input image data, type CV_8UC1, src height must be a multiple of 2
21-
* @param _dst The output image data, type CV_8UC1
22-
*/
23-
CV_EXPORTS_W void resizeDownBy2(cv::InputArray _src, cv::OutputArray _dst);
24-
25-
/**
26-
* @brief Down-scale the image by averaging each 4x4 pixel block.
27-
* This function is not bit-exact with cv::resize but provides faster execution time on Qualcomm's processor.
28-
* @param _src The first input image data, type CV_8UC1, src height must be a multiple of 4
29-
* @param _dst The output image data, type CV_8UC1
30-
*/
31-
CV_EXPORTS_W void resizeDownBy4(cv::InputArray _src, cv::OutputArray _dst);
18+
* @brief Down-scales the image using specified scaling factors or dimensions.
19+
* This function supports both single-channel (CV_8UC1) and two-channel (CV_8UC2) images.
20+
*
21+
* @param _src The input image data, type CV_8UC1 or CV_8UC2.
22+
* @param _dst The output image data, type CV_8UC1 or CV_8UC2.
23+
* @param dsize The desired size of the output image. If empty, it is calculated using inv_scale_x and inv_scale_y.
24+
* @param inv_scale_x The inverse scaling factor for the width. If dsize is provided, this parameter is ignored.
25+
* @param inv_scale_y The inverse scaling factor for the height. If dsize is provided, this parameter is ignored.
26+
*
27+
* @note If dsize is not specified, inv_scale_x and inv_scale_y must be strictly positive.
28+
*/
29+
CV_EXPORTS_W void resizeDown(cv::InputArray _src, cv::OutputArray _dst, Size dsize, double inv_scale_x, double inv_scale_y);
3230

3331
//! @}
3432

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef OPENCV_FASTCV_THRESH_DSP_HPP
7+
#define OPENCV_FASTCV_THRESH_DSP_HPP
8+
9+
#include <opencv2/core.hpp>
10+
11+
namespace cv {
12+
namespace fastcv {
13+
namespace dsp {
14+
15+
//! @addtogroup fastcv
16+
//! @{
17+
18+
/**
19+
* @brief Binarizes a grayscale image using Otsu's method.
20+
* Sets the pixel to max(255) if it's value is greater than the threshold;
21+
* else, set the pixel to min(0). The threshold is searched that minimizes
22+
* the intra-class variance (the variance within the class).
23+
*
24+
* @param _src Input 8-bit grayscale image. Size of buffer is srcStride*srcHeight bytes.
25+
* @param _dst Output 8-bit binarized image. Size of buffer is dstStride*srcHeight bytes.
26+
* @param type Threshold type that can be either 0 or 1.
27+
* NOTE: For threshold type=0, the pixel is set as
28+
* maxValue if it's value is greater than the threshold; else, it is set as zero.
29+
* For threshold type=1, the pixel is set as zero if it's
30+
* value is greater than the threshold; else, it is set as maxValue.
31+
*/
32+
CV_EXPORTS void thresholdOtsu(InputArray _src, OutputArray _dst, bool type);
33+
34+
//! @}
35+
} // dsp::
36+
} // fastcv::
37+
} // cv::
38+
39+
#endif // OPENCV_FASTCV_THRESH_DSP_HPP

0 commit comments

Comments
 (0)