Skip to content

Commit 3a962dc

Browse files
committed
Adding Fastcv extension for normalizeLocalBox u8 and f32
1 parent fa1dbfd commit 3a962dc

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

modules/fastcv/include/opencv2/fastcv/blur.hpp

Lines changed: 17 additions & 1 deletion
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) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -58,6 +58,22 @@ CV_EXPORTS_W void filter2D(InputArray _src, OutputArray _dst, int ddepth, InputA
5858
CV_EXPORTS_W void sepFilter2D(InputArray _src, OutputArray _dst, int ddepth, InputArray _kernelX, InputArray _kernelY);
5959
//! @}
6060

61+
//! @addtogroup fastcv
62+
//! @{
63+
64+
/**
65+
* @brief Calculates the local subtractive and contrastive normalization of the image.
66+
* Each pixel of the image is normalized by the mean and standard deviation of the patch centred at the pixel.
67+
* It is optimized for Qualcomm's processors.
68+
* @param src Input image, should have one channel CV_8U or CV_32F
69+
* @param dst Output array, should be one channel, CV_8S if src of type CV_8U, or CV_32F if src of CV_32F
70+
* @param pSize Patch size for mean and std dev calculation
71+
* @param useStdDev If 1, bot mean and std dev will be used for normalization, if 0, only mean used
72+
*/
73+
CV_EXPORTS_W void normalizeLocalBox(InputArray _src, OutputArray _dst, Size pSize, bool useStdDev);
74+
75+
//! @}
76+
6177
} // fastcv::
6278
} // cv::
6379

modules/fastcv/perf/perf_blur.cpp

Lines changed: 31 additions & 1 deletion
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) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -120,4 +120,34 @@ PERF_TEST_P(SepFilter2DPerfTest, run,
120120
SANITY_CHECK_NOTHING();
121121
}
122122

123+
typedef perf::TestBaseWithParam<tuple<Size, int, Size, int>> NormalizeLocalBoxPerfTest;
124+
125+
PERF_TEST_P(NormalizeLocalBoxPerfTest, run,
126+
::testing::Combine(::testing::Values(perf::szVGA, perf::sz720p, perf::sz1080p), // image size
127+
::testing::Values(CV_8U,CV_32F), // src image depth
128+
::testing::Values(Size(3,3),Size(5,5)), // patch size
129+
::testing::Values(0,1) // use std dev or not
130+
)
131+
)
132+
{
133+
cv::Size srcSize = get<0>(GetParam());
134+
int depth = get<1>(GetParam());
135+
Size sz = get<2>(GetParam());
136+
bool useStdDev = get<3>(GetParam());
137+
138+
cv::Mat src(srcSize, depth);
139+
cv::Mat dst;
140+
RNG& rng = cv::theRNG();
141+
cvtest::randUni(rng, src, Scalar::all(0), Scalar::all(255));
142+
143+
while (next())
144+
{
145+
startTimer();
146+
cv::fastcv::normalizeLocalBox(src, dst, sz, useStdDev);
147+
stopTimer();
148+
}
149+
150+
SANITY_CHECK_NOTHING();
151+
}
152+
123153
} // namespace

modules/fastcv/src/blur.cpp

Lines changed: 22 additions & 1 deletion
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) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -361,5 +361,26 @@ void sepFilter2D(InputArray _src, OutputArray _dst, int ddepth, InputArray _kern
361361
}
362362
}
363363

364+
void normalizeLocalBox(InputArray _src, OutputArray _dst, Size pSize, bool useStdDev)
365+
{
366+
CV_Assert(!_src.empty());
367+
int type = _src.type();
368+
CV_Assert(type == CV_8UC1 || type == CV_32FC1);
369+
370+
Size size = _src.size();
371+
int dst_type = type == CV_8UC1 ? CV_8SC1 : CV_32FC1;
372+
_dst.create(size, dst_type);
373+
374+
Mat src = _src.getMat();
375+
Mat dst = _dst.getMat();
376+
377+
if(type == CV_8UC1)
378+
fcvNormalizeLocalBoxu8(src.data, src.cols, src.rows, src.step[0],
379+
pSize.width, pSize.height, useStdDev, (int8_t*)dst.data, dst.step[0]);
380+
else if(type == CV_32FC1)
381+
fcvNormalizeLocalBoxf32((float*)src.data, src.cols, src.rows, src.step[0],
382+
pSize.width, pSize.height, useStdDev, (float*)dst.data, dst.step[0]);
383+
}
384+
364385
} // fastcv::
365386
} // cv::

0 commit comments

Comments
 (0)