Skip to content

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

Open
wants to merge 8 commits into
base: 4.x
Choose a base branch
from

Conversation

quic-apreetam
Copy link

@quic-apreetam quic-apreetam commented Apr 29, 2025

Merge with opencv/opencv#27290

Detailed Description

This PR introduces FastCV DSP Extension APIs within the 'cv::fastcv::dsp' namespace.
The following APIs have been added:

  1. fcvdspinit: Initializes the FastCV DSP environment.
  2. fcvdspdeinit: Deinitializes the FastCV DSP environment.
  3. sumOfAbsoluteDiffs: Computes the sum of absolute differences of an image against an 8x8 template.
  4. thresholdOtsu: Binarizes a grayscale image using Otsu's method.
  5. FFT: Computes the 1D or 2D Fast Fourier Transform of a real-valued matrix.
  6. IFFT: Computes the 1D or 2D Inverse Fast Fourier Transform of a complex-valued matrix.
  7. canny: Applies the Canny edge detector to an 8-bit grayscale image.
  8. filter2D: Applies a generic 2D filter to an image.

The QcAllocator has been added to manage memory allocations on Qualcomm's Chipsets. This allocator ensures that matrices are allocated using the Qualcomm hardware memory allocator, providing efficient DSP operations.

Requires binary from opencv/opencv_3rdparty#95

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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

@asmorkalov
Copy link
Contributor

Java bindings generator does not handle namespaces well:

[255/3358] Generating opencv-4120.jar
FAILED: CMakeFiles/dephelper/opencv_java_jar bin/opencv-4120.jar 
cd /home/ci/build/modules/java/jar/opencv && /bin/ant -noinput -k jar && /usr/bin/cmake -E touch /home/ci/build/CMakeFiles/dephelper/opencv_java_jar
Buildfile: /home/ci/build/modules/java/jar/opencv/build.xml

jar:
    [javac] Compiling 299 source files to /home/ci/build/modules/java/jar/opencv/build/classes
    [javac] /home/ci/build/modules/java/jar/opencv/java/org/opencv/fastcv/Fastcv.java:715: error: method filter2D(Mat,Mat,int,Mat) is already defined in class Fastcv
    [javac]     public static void filter2D(Mat _src, Mat _dst, int ddepth, Mat _kernel) {
    [javac]                        ^
    [javac] /home/ci/build/modules/java/jar/opencv/java/org/opencv/fastcv/Fastcv.java:798: error: method FFT(Mat,Mat) is already defined in class Fastcv
    [javac]     public static void FFT(Mat src, Mat dst) {
    [javac]                        ^
    [javac] /home/ci/build/modules/java/jar/opencv/java/org/opencv/fastcv/Fastcv.java:818: error: method IFFT(Mat,Mat) is already defined in class Fastcv
    [javac]     public static void IFFT(Mat src, Mat dst) {
    [javac]                        ^
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] 3 errors
Target 'jar' failed with message 'Compile failed; see the compiler error output for details.'.

BUILD FAILED

If I understand correctly, DSP part is not usable from Java code (no way to manage allocators in Java). I propose to replace CV_EXPORTS_W with CV_EXPORTS.

@quic-apreetam
Copy link
Author

Java bindings generator does not handle namespaces well:

[255/3358] Generating opencv-4120.jar
FAILED: CMakeFiles/dephelper/opencv_java_jar bin/opencv-4120.jar 
cd /home/ci/build/modules/java/jar/opencv && /bin/ant -noinput -k jar && /usr/bin/cmake -E touch /home/ci/build/CMakeFiles/dephelper/opencv_java_jar
Buildfile: /home/ci/build/modules/java/jar/opencv/build.xml

jar:
    [javac] Compiling 299 source files to /home/ci/build/modules/java/jar/opencv/build/classes
    [javac] /home/ci/build/modules/java/jar/opencv/java/org/opencv/fastcv/Fastcv.java:715: error: method filter2D(Mat,Mat,int,Mat) is already defined in class Fastcv
    [javac]     public static void filter2D(Mat _src, Mat _dst, int ddepth, Mat _kernel) {
    [javac]                        ^
    [javac] /home/ci/build/modules/java/jar/opencv/java/org/opencv/fastcv/Fastcv.java:798: error: method FFT(Mat,Mat) is already defined in class Fastcv
    [javac]     public static void FFT(Mat src, Mat dst) {
    [javac]                        ^
    [javac] /home/ci/build/modules/java/jar/opencv/java/org/opencv/fastcv/Fastcv.java:818: error: method IFFT(Mat,Mat) is already defined in class Fastcv
    [javac]     public static void IFFT(Mat src, Mat dst) {
    [javac]                        ^
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] 3 errors
Target 'jar' failed with message 'Compile failed; see the compiler error output for details.'.

BUILD FAILED

If I understand correctly, DSP part is not usable from Java code (no way to manage allocators in Java). I propose to replace CV_EXPORTS_W with CV_EXPORTS.

sure @asmorkalov , will change CV_EXPORTS_W with CV_EXPORTS

@quic-apreetam
Copy link
Author

hi @asmorkalov changes updated. Please review

Copy link
Author

@quic-apreetam quic-apreetam left a comment

Choose a reason for hiding this comment

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

.

Copy link
Author

@quic-apreetam quic-apreetam left a comment

Choose a reason for hiding this comment

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

Corrected Typo and removed redundant break @asmorkalov thanks

@quic-apreetam quic-apreetam requested a review from asmorkalov May 5, 2025 09:05
Copy link

@qc-apreetam qc-apreetam left a comment

Choose a reason for hiding this comment

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

.

@qc-apreetam
Copy link

hi @asmorkalov , we are getting undefined reference to `dlerror'/'dlsym'/'dlopen'/'dlclose' errors https://github.com/opencv/opencv_contrib/actions/runs/14832679408/job/41640009265

looks like the library libdl is missing on the build machine

@asmorkalov
Copy link
Contributor

It's system linker and cannot be missing. It should be mentioned in linkage list in CMake.

@quic-apreetam
Copy link
Author

It's system linker and cannot be missing. It should be mentioned in linkage list in CMake.
hi @asmorkalov
updating line:8 in https://github.com/opencv/opencv_contrib/blob/4.x/modules/fastcv/CMakeLists.txt
to
ocv_target_link_libraries(${the_module} ${FASTCV_LIBRARY} dl) should be sufficient?

@asmorkalov
Copy link
Contributor

I recommend to add the dependency, when FastCV is added to cmake here: https://github.com/opencv/opencv/blob/4.x/cmake/OpenCVFindLibsPerf.cmake#L200. HAL links the same library and we may get similar linkage issues in other places.

See similar discussion on Stackoverflow with ready solution:
https://stackoverflow.com/questions/36922635/cmake-add-dependency-to-imported-library

@quic-apreetam
Copy link
Author

I recommend to add the dependency, when FastCV is added to cmake here: https://github.com/opencv/opencv/blob/4.x/cmake/OpenCVFindLibsPerf.cmake#L200. HAL links the same library and we may get similar linkage issues in other places.

See similar discussion on Stackoverflow with ready solution: https://stackoverflow.com/questions/36922635/cmake-add-dependency-to-imported-library

hi @asmorkalov , thanks for the suggestion.

updated "cmake/OpenCVFindLibsPerf.cmake" to link libdl
this change is a part of : opencv/opencv#27269

@quic-apreetam
Copy link
Author

quic-apreetam commented May 7, 2025

hi @asmorkalov , we still see undefined reference to `dlerror'/'dlsym'/'dlopen'/'dlclose' errors in https://github.com/opencv/opencv_contrib/actions/runs/14832679408/job/41789805574?pr=3931

I think the opencv changes are not merged before Build and Test
Run OPENCV_FORK=$(git ls-remote --heads "https://github.com/quic-apreetam/opencv" "apreetam_5thPost") || true
fatal: could not read Username for 'https://github.com/': No such device or address
No merge since quic-apreetam/opencv does not have branch apreetam_5thPost

Also, as we already updated https://github.com/opencv/opencv/blob/4.x/cmake/OpenCVFindLibsPerf.cmake#L200

we did not make any change in https://github.com/opencv/opencv_contrib/blob/4.x/modules/fastcv/CMakeLists.txt
should we still update this file?

@asmorkalov
Copy link
Contributor

Hm.., it's not your repo, it's CodeLinaro :(

@quic-apreetam
Copy link
Author

Hm.., it's not your repo, it's CodeLinaro :(

hi @asmorkalov please help to explain, not sure if I understand the problem, anything required to be done from my side?

@asmorkalov
Copy link
Contributor

Nothing from your side. Our script looks for extra branches to merge in your own namespace, but not CodeLinaro. We will test things manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants