-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add FastCV DSP Initialization, QcAllocator and FastCV DSP Extension APIs #3931
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7c342d6
Add QcAllocator and DSP Init and Deinit Functions
quic-apreetam 2bed4bc
Added sumOfAbsoluteDiffs DSP API with Accuracy and Perf Test
quic-apreetam 2ea338a
Add thresholdOtSu DSP API with Accuracy and Perf Test
quic-apreetam 51f92b0
Add FFT and IFFT DSP API with Accuracy and Perf Test
quic-apreetam ffa4c84
Add canny DSP API with Accuracy and Perf Test
quic-apreetam 350f7f9
Add filter2D DSP API with Accuracy and Perf Test
quic-apreetam a0c5c8c
Remove parallel_for_ from filter2D dsp API, update mat allocation check
quic-apreetam a0e609f
Remove redundant break and correct typo
quic-apreetam b6a49a8
Added extra test tag for Qualcomm DSP (disabled by default)
asmorkalov e5c7e07
Fix Documentation Warn
quic-apreetam 015033d
Switch to locally defined skip tag in FastCV tests.
asmorkalov 9300c5f
Merge remote-tracking branch 'asmorkalov/as/test_tag_dsp' into apreet…
quic-apreetam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef OPENCV_FASTCV_ALLOCATOR_HPP | ||
#define OPENCV_FASTCV_ALLOCATOR_HPP | ||
|
||
#include <opencv2/core.hpp> | ||
#include <set> | ||
#include <mutex> | ||
|
||
namespace cv { | ||
namespace fastcv { | ||
|
||
//! @addtogroup fastcv | ||
//! @{ | ||
|
||
/** | ||
* @brief Resource manager for FastCV allocations. | ||
* This class manages active allocations. | ||
*/ | ||
class QcResourceManager { | ||
public: | ||
static QcResourceManager& getInstance(); | ||
|
||
void addAllocation(void* ptr); | ||
void removeAllocation(void* ptr); | ||
|
||
private: | ||
QcResourceManager() = default; | ||
std::set<void*> activeAllocations; | ||
std::mutex resourceMutex; | ||
}; | ||
|
||
/** | ||
* @brief Qualcomm's custom allocator. | ||
* This allocator uses Qualcomm's memory management functions. | ||
*/ | ||
class QcAllocator : public cv::MatAllocator { | ||
public: | ||
QcAllocator(); | ||
~QcAllocator(); | ||
|
||
cv::UMatData* allocate(int dims, const int* sizes, int type, void* data0, size_t* step, cv::AccessFlag flags, cv::UMatUsageFlags usageFlags) const CV_OVERRIDE; | ||
bool allocate(cv::UMatData* u, cv::AccessFlag accessFlags, cv::UMatUsageFlags usageFlags) const CV_OVERRIDE; | ||
void deallocate(cv::UMatData* u) const CV_OVERRIDE; | ||
}; | ||
|
||
/** | ||
* @brief Gets the default Qualcomm's allocator. | ||
* This function returns a pointer to the default Qualcomm's allocator, which is optimized | ||
* for use with DSP. | ||
* | ||
* @return Pointer to the default FastCV allocator. | ||
*/ | ||
CV_EXPORTS cv::MatAllocator* getQcAllocator(); | ||
|
||
//! @} | ||
|
||
} // namespace fastcv | ||
} // namespace cv | ||
|
||
#endif // OPENCV_FASTCV_ALLOCATOR_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef OPENCV_FASTCV_BLUR_DSP_HPP | ||
#define OPENCV_FASTCV_BLUR_DSP_HPP | ||
|
||
#include <opencv2/core.hpp> | ||
|
||
namespace cv { | ||
namespace fastcv { | ||
namespace dsp { | ||
/** | ||
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions | ||
*/ | ||
|
||
/** | ||
* @brief Filter an image with non-separable kernel | ||
* @param _src Intput image with type CV_8UC1, src size should be greater than 176*144 | ||
* @param _dst Output image with type CV_8UC1, CV_16SC1 or CV_32FC1 | ||
* @param ddepth The depth of output image | ||
* @param _kernel Filer kernel data | ||
* | ||
* @sa Filter2D | ||
*/ | ||
CV_EXPORTS_W void filter2D(InputArray _src, OutputArray _dst, int ddepth, InputArray _kernel); | ||
|
||
//! @} | ||
} // dsp:: | ||
} // fastcv:: | ||
} // cv:: | ||
|
||
#endif // OPENCV_FASTCV_BLUR_DSP_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef OPENCV_FASTCV_DSP_INIT_HPP | ||
#define OPENCV_FASTCV_DSP_INIT_HPP | ||
|
||
#include <opencv2/core.hpp> | ||
|
||
namespace cv { | ||
namespace fastcv { | ||
namespace dsp { | ||
|
||
//! @addtogroup fastcv | ||
//! @{ | ||
|
||
/** | ||
* @brief Initializes the FastCV DSP environment. | ||
* | ||
* This function sets up the necessary environment and resources for the DSP to operate. | ||
* It must be called once at the very beginning of the use case or program to ensure that | ||
* the DSP is properly initialized before any DSP-related operations are performed. | ||
* | ||
* @note This function must be called at the start of the use case or program, before any | ||
* DSP-related operations. | ||
* | ||
* @return int Returns 0 on success, and a non-zero value on failure. | ||
*/ | ||
CV_EXPORTS_W int fcvdspinit(); | ||
|
||
/** | ||
* @brief Deinitializes the FastCV DSP environment. | ||
* | ||
* This function releases the resources and environment set up by the 'fcvdspinit' function. | ||
* It should be called before the use case or program exits to ensure that all DSP resources | ||
* are properly cleaned up and no memory leaks occur. | ||
* | ||
* @note This function must be called at the end of the use case or program, after all DSP-related | ||
* operations are complete. | ||
*/ | ||
CV_EXPORTS_W void fcvdspdeinit(); | ||
//! @} | ||
|
||
} // dsp:: | ||
} // fastcv:: | ||
} // cv:: | ||
|
||
#endif // OPENCV_FASTCV_DSP_INIT_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef OPENCV_FASTCV_EDGES_DSP_HPP | ||
#define OPENCV_FASTCV_EDGES_DSP_HPP | ||
|
||
#include "opencv2/core/mat.hpp" | ||
|
||
namespace cv { | ||
namespace fastcv { | ||
namespace dsp { | ||
|
||
/** | ||
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions | ||
*/ | ||
|
||
//! @addtogroup fastcv | ||
//! @{ | ||
|
||
/** | ||
* @brief Canny edge detector applied to a 8 bit grayscale image | ||
* @param _src Input image with type CV_8UC1 | ||
* @param _dst Output 8-bit image containing the edge detection results | ||
* @param lowThreshold First threshold | ||
* @param highThreshold Second threshold | ||
* @param apertureSize The Sobel kernel size for calculating gradient. Supported sizes are 3, 5 and 7. | ||
* @param L2gradient L2 Gradient or L1 Gradient | ||
*/ | ||
CV_EXPORTS_W void canny(InputArray _src, OutputArray _dst, int lowThreshold, int highThreshold, int apertureSize = 3, bool L2gradient = false); | ||
//! @} | ||
|
||
} // dsp:: | ||
} // fastcv:: | ||
} // cv:: | ||
|
||
#endif //OPENCV_FASTCV_EDGES_DSP_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef OPENCV_FASTCV_FFT_DSP_HPP | ||
#define OPENCV_FASTCV_FFT_DSP_HPP | ||
|
||
#include <opencv2/core.hpp> | ||
|
||
namespace cv { | ||
namespace fastcv { | ||
namespace dsp { | ||
|
||
//! @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); | ||
|
||
//! @} | ||
|
||
} // dsp:: | ||
} // fastcv:: | ||
} // cv:: | ||
|
||
#endif // OPENCV_FASTCV_FFT_DSP_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef OPENCV_FASTCV_SAD_HPP | ||
#define OPENCV_FASTCV_SAD_HPP | ||
|
||
#include <opencv2/core.hpp> | ||
|
||
namespace cv { | ||
namespace fastcv { | ||
namespace dsp { | ||
|
||
/** | ||
* @defgroup fastcv Module-wrapper for FastCV hardware accelerated functions | ||
*/ | ||
|
||
//! @addtogroup fastcv | ||
//! @{ | ||
/** | ||
* @brief Sum of absolute differences of an image against an 8x8 template. | ||
* @param _patch The first input image data, type CV_8UC1 | ||
* @param _src The input image data, type CV_8UC1 | ||
* @param _dst The output image data, type CV_16UC1 | ||
*/ | ||
CV_EXPORTS_W void sumOfAbsoluteDiffs(cv::InputArray _patch, cv::InputArray _src, cv::OutputArray _dst); | ||
//! @} | ||
|
||
} // dsp:: | ||
} // fastcv:: | ||
} // cv:: | ||
|
||
#endif // OPENCV_FASTCV_SAD_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef OPENCV_FASTCV_THRESH_DSP_HPP | ||
#define OPENCV_FASTCV_THRESH_DSP_HPP | ||
|
||
#include <opencv2/core.hpp> | ||
|
||
namespace cv { | ||
namespace fastcv { | ||
namespace dsp { | ||
|
||
//! @addtogroup fastcv | ||
//! @{ | ||
|
||
/** | ||
* @brief Binarizes a grayscale image using Otsu's method. | ||
* Sets the pixel to max(255) if it's value is greater than the threshold; | ||
* else, set the pixel to min(0). The threshold is searched that minimizes | ||
* the intra-class variance (the variance within the class). | ||
* | ||
* @param _src Input 8-bit grayscale image. Size of buffer is srcStride*srcHeight bytes. | ||
* @param _dst Output 8-bit binarized image. Size of buffer is dstStride*srcHeight bytes. | ||
* @param type Threshold type that can be either 0 or 1. | ||
* NOTE: For threshold type=0, the pixel is set as | ||
* maxValue if it's value is greater than the threshold; else, it is set as zero. | ||
* For threshold type=1, the pixel is set as zero if it's | ||
* value is greater than the threshold; else, it is set as maxValue. | ||
*/ | ||
CV_EXPORTS_W void thresholdOtsu(InputArray _src, OutputArray _dst, bool type); | ||
|
||
//! @} | ||
} // dsp:: | ||
} // fastcv:: | ||
} // cv:: | ||
|
||
#endif // OPENCV_FASTCV_THRESH_DSP_HPP |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.