Skip to content
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

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

Conversation

sssanjee-quic
Copy link

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

Change-Id: I721b810181dd9127221b6e2182d7aad5ac679b68
Added FastCV Extension code for Opencv APIs
Copy link
Contributor

@savuor savuor left a comment

Choose a reason for hiding this comment

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

The rest is OK, waiting for other wrapped functions to be added.

The tests can be merged as-is, without fixing all my comments. But I still have to leave these comments so that they can be fixed in the future.


# here you can change the library to a specific one
set(FASTCV_LIB "/libs/Android/lib64/libfastcvopt.so")

Copy link
Contributor

Choose a reason for hiding this comment

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

Extra line


This module provides wrappers for several FastCV functions not covered by the corresponding HAL in OpenCV.
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

This behavior was changed, please change this part of readme.
Now CMake will just emit a warning if the platform is not ARM but won't stop configuration. Any attempts to link under any platform but ARM would lead to a failure. The reason is to let various IDEs run their code analysis tools that require the code to be compiled at least.

* @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);
Copy link
Contributor

Choose a reason for hiding this comment

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

_InputArray src2 -> InputArray src2


/**
* @brief Applies Bilateral filter to an image considering d-pixel diameter of each pixel's neighborhood.
This filter does not work inplace.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be checked in the code with something like CV_Assert(src.data != dst.data);

* @brief Calculates all of the moments up to the third order of the image pixels' intensities
The results are returned in the structure cv::Moments.
* @param _src Input image with type CV_8UC1, CV_32SC1, CV_32FC1
* @param binary If 1, binary image (0x00-black, oxff-white); if 0, grayscale image
Copy link
Contributor

Choose a reason for hiding this comment

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

-> If true, assumes the image to be binary (0x00 for black, 0xff for white), otherwise assumes the image to be grayscale

cv::minMaxLoc(diffImage, nullptr, &maxVal);

// Assert if the difference is acceptable (max difference should be less than 10)
CV_Assert(maxVal < 10 && "Difference between images is too high!");
Copy link
Contributor

Choose a reason for hiding this comment

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

The same about L_inf norm

cv::minMaxLoc(diffImage, nullptr, &maxVal);

// Assert if the difference is acceptable (max difference should be less than 10)
CV_Assert(maxVal < 10 && "Difference between images is too high!");
Copy link
Contributor

Choose a reason for hiding this comment

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

The same about L_inf norm

cv::minMaxLoc(diffImage, nullptr, &maxVal);

// Assert if the difference is acceptable (max difference should be less than 10)
CV_Assert(maxVal < 10 && "Difference between images is too high!");
Copy link
Contributor

Choose a reason for hiding this comment

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

The same about L_inf norm

cv::fastcv::resizeDownBy2(inputImage, resized_image);

// Check if the output size is correct
EXPECT_EQ(resized_image.size().width, size.width * 0.5);
Copy link
Contributor

Choose a reason for hiding this comment

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

These checks can be moved to the accuracy test

cv::fastcv::resizeDownBy4(inputImage, resized_image);

// Check if the output size is correct
EXPECT_EQ(resized_image.size().width, size.width * 0.25);
Copy link
Contributor

Choose a reason for hiding this comment

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

These checks can be moved to the accuracy test

cleanup and added make rules to download the
fastcv bins from the 3rdparty repo

Change-Id: I9a9db68a310263658ec93ea299ea37860d07c507
Fastcv ext changes for Opencv Acceleration
Comment on lines +1 to +7
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")
Copy link
Contributor

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.

Copy link

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

Comment on lines +9 to +12
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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Let it be called from the root cmake in main repo.

Copy link

Choose a reason for hiding this comment

The 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

FastCV extension for OpenCV
===========================

This module provides wrappers for several FastCV functions not covered by the corresponding HAL in OpenCV.
Copy link
Contributor

Choose a reason for hiding this comment

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

or have implementation incompatible with OpenCV.

Copy link

Choose a reason for hiding this comment

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

will add

@@ -0,0 +1,35 @@
function(download_fastcv root_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be in main CMake.

Copy link

Choose a reason for hiding this comment

The 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

* @param _src Input image with type CV_8UC1, CV_32SC1, CV_32FC1
* @param binary If 1, binary image (0x00-black, oxff-white); if 0, grayscale image
*/
CV_EXPORTS_W cv::Moments moments(InputArray _src, bool binary);
Copy link
Contributor

Choose a reason for hiding this comment

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

Moments are part of HAL and already wrapped, right?

Comment on lines +105 to +107
double normL2 = cv::norm(diffs, NORM_L2) / nClusters;

EXPECT_LT(normL2, 0.392);
Copy link
Contributor

Choose a reason for hiding this comment

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

Average distance hides corner cases, e.g. all points, besides one are the same, but the last one is significant outlier. The check should be reworked.

Comment on lines +114 to +115
double normH = cv::norm(bindings8u, trueBindings8u, NORM_HAMMING) / nPts;
EXPECT_LT(normH, 0.658);
Copy link
Contributor

Choose a reason for hiding this comment

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

The same

int border = std::get<2>(p);
bool nmsEnabled = std::get<3>(p);

cv::Mat src = imread(cvtest::findDataFile("cv/shared/lena.png"), cv::IMREAD_GRAYSCALE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Lena note.


RNG& rng = cv::theRNG();
Mat src(size, CV_8UC1);
cvtest::randUni(rng, src, Scalar::all(0), Scalar::all(256));
Copy link
Contributor

Choose a reason for hiding this comment

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

256 - overflow.

namespace cv {
namespace fastcv {

bool isInitialized = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

The same initialization issue as in main repo.

Choose a reason for hiding this comment

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

will add singleton similar to main

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

Successfully merging this pull request may close these issues.

4 participants