Merge pull request #3845 from CodeLinaro:adsha_2ndPost
FastCV Extension code for OpenCV 2ndpost-2 #3845 ### Description: - Add support for cv::fastcv::calcHist Depends on: [opencv/opencv_contrib#3844](https://github.com/opencv/opencv_contrib/pull/3844) Depends on: [opencv/opencv#26619](https://github.com/opencv/opencv/pull/26619) Requires binary from: [opencv/opencv_3rdparty#90](https://github.com/opencv/opencv_3rdparty/pull/90) ### 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 CMakepull/3854/head
parent
67815e94c8
commit
a00b3f3296
10 changed files with 217 additions and 81 deletions
@ -0,0 +1,29 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef OPENCV_FASTCV_HISTOGRAM_HPP |
||||||
|
#define OPENCV_FASTCV_HISTOGRAM_HPP |
||||||
|
|
||||||
|
#include <opencv2/core.hpp> |
||||||
|
|
||||||
|
namespace cv { |
||||||
|
namespace fastcv { |
||||||
|
|
||||||
|
//! @addtogroup fastcv
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculates histogram of input image. This function implements specific use case of |
||||||
|
* 256-bin histogram calculation for 8u single channel images in an optimized way. |
||||||
|
* @param _src Intput image with type CV_8UC1 |
||||||
|
* @param _hist Output histogram of type int of 256 bins |
||||||
|
*/ |
||||||
|
CV_EXPORTS_W void calcHist( InputArray _src, OutputArray _hist ); |
||||||
|
//! @}
|
||||||
|
|
||||||
|
} // fastcv::
|
||||||
|
} // cv::
|
||||||
|
|
||||||
|
#endif // OPENCV_FASTCV_HISTOGRAM_HPP
|
@ -0,0 +1,36 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "perf_precomp.hpp" |
||||||
|
|
||||||
|
namespace opencv_test { |
||||||
|
|
||||||
|
typedef std::tuple<cv::Size> HistogramPerfParams; |
||||||
|
typedef perf::TestBaseWithParam<HistogramPerfParams> HistogramPerfTest; |
||||||
|
|
||||||
|
|
||||||
|
PERF_TEST_P(HistogramPerfTest, run, |
||||||
|
testing::Values(perf::szQVGA, perf::szVGA, perf::sz720p, perf::sz1080p) |
||||||
|
) |
||||||
|
{ |
||||||
|
auto p = GetParam(); |
||||||
|
cv::Size size = std::get<0>(p); |
||||||
|
|
||||||
|
RNG& rng = cv::theRNG(); |
||||||
|
Mat src(size, CV_8UC1); |
||||||
|
cvtest::randUni(rng, src, Scalar::all(0), Scalar::all(255)); |
||||||
|
Mat hist(1, 256, CV_32SC1); |
||||||
|
|
||||||
|
while (next()) |
||||||
|
{ |
||||||
|
startTimer(); |
||||||
|
cv::fastcv::calcHist(src, hist); |
||||||
|
stopTimer(); |
||||||
|
} |
||||||
|
|
||||||
|
SANITY_CHECK_NOTHING(); |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace
|
@ -0,0 +1,74 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "precomp.hpp" |
||||||
|
|
||||||
|
namespace cv { |
||||||
|
namespace fastcv { |
||||||
|
|
||||||
|
class FcvHistogramLoop_Invoker : public cv::ParallelLoopBody |
||||||
|
{ |
||||||
|
public: |
||||||
|
|
||||||
|
FcvHistogramLoop_Invoker(const uchar * src_data_, size_t src_step_, int width_, int height_, int32_t* gl_hist_, int stripeHeight_, cv::Mutex* histogramLock, int nStripes_): |
||||||
|
cv::ParallelLoopBody(), src_data(src_data_), src_step(src_step_), width(width_), height(height_), gl_hist(gl_hist_), stripeHeight(stripeHeight_), histogramLock_(histogramLock), nStripes(nStripes_) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
virtual void operator()(const cv::Range& range) const CV_OVERRIDE |
||||||
|
{ |
||||||
|
int height_ = stripeHeight; |
||||||
|
if(range.end == nStripes) |
||||||
|
height_ += (height % nStripes); |
||||||
|
const uchar* yS = src_data; |
||||||
|
int32_t l_hist[256] = {0}; |
||||||
|
fcvImageIntensityHistogram(yS, src_step, 0, range.start, width, height_, l_hist); |
||||||
|
cv::AutoLock lock(*histogramLock_); |
||||||
|
|
||||||
|
for( int i = 0; i < 256; i++ ) |
||||||
|
gl_hist[i] += l_hist[i]; |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
const uchar * src_data; |
||||||
|
const size_t src_step; |
||||||
|
const int width; |
||||||
|
const int height; |
||||||
|
int32_t *gl_hist; |
||||||
|
int ret; |
||||||
|
int stripeHeight; |
||||||
|
cv::Mutex* histogramLock_; |
||||||
|
int nStripes; |
||||||
|
|
||||||
|
FcvHistogramLoop_Invoker(const FcvHistogramLoop_Invoker &); // = delete;
|
||||||
|
const FcvHistogramLoop_Invoker& operator= (const FcvHistogramLoop_Invoker &); // = delete;
|
||||||
|
}; |
||||||
|
|
||||||
|
void calcHist( InputArray _src, OutputArray _hist ) |
||||||
|
{ |
||||||
|
INITIALIZATION_CHECK; |
||||||
|
|
||||||
|
CV_Assert(!_src.empty()); |
||||||
|
int type = _src.type(); |
||||||
|
CV_Assert(type == CV_8UC1); |
||||||
|
|
||||||
|
_hist.create( cv::Size(256, 1), CV_32SC1 ); |
||||||
|
Mat src = _src.getMat(); |
||||||
|
Mat hist = _hist.getMat(); |
||||||
|
|
||||||
|
for( int i = 0; i < 256; i++ ) |
||||||
|
hist.ptr<int>()[i] = 0; |
||||||
|
|
||||||
|
cv::Mutex histogramLockInstance; |
||||||
|
|
||||||
|
int nStripes = cv::getNumThreads(); |
||||||
|
int stripeHeight = src.rows / nStripes; |
||||||
|
|
||||||
|
cv::parallel_for_(cv::Range(0, nStripes), |
||||||
|
FcvHistogramLoop_Invoker(src.data, src.step[0], src.cols, src.rows, hist.ptr<int>(), stripeHeight, &histogramLockInstance, nStripes), nStripes); |
||||||
|
} |
||||||
|
|
||||||
|
} // fastcv::
|
||||||
|
} // cv::
|
Loading…
Reference in new issue