Skip to content

Commit 674cec1

Browse files
committed
Merge pull request #3613 from amishutin:signal_module
2 parents c7602a8 + 105e514 commit 674cec1

File tree

13 files changed

+696
-0
lines changed

13 files changed

+696
-0
lines changed

modules/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ $ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -D BUILD_opencv_<r
7272

7373
- **saliency**: Saliency API -- Where humans would look in a scene. Has routines for static, motion and "objectness" saliency.
7474

75+
- **signal**: Signal processing algorithms
76+
7577
- **sfm**: Structure from Motion -- This module contains algorithms to perform 3d reconstruction from 2d images. The core of the module is a light version of Libmv.
7678

7779
- **shape**: Shape Distance and Matching

modules/signal/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(the_description "Signal processing algorithms")
2+
ocv_define_module(signal opencv_core WRAP python)

modules/signal/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Signal Processing algorithms
2+
================================================
3+
4+
Signal resampling done with cubic interpolation and low-pass filtering
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html
4+
#ifndef OPENCV_SIGNAL_HPP
5+
#define OPENCV_SIGNAL_HPP
6+
7+
/**
8+
* @defgroup signal Signal Processing
9+
* @{
10+
* This module includes signal processing algorithms.
11+
* @}
12+
*/
13+
14+
#include "opencv2/core.hpp"
15+
#include "opencv2/signal/signal_resample.hpp"
16+
17+
#endif
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html
4+
#ifndef OPENCV_SIGNAL_SIGNAL_RESAMPLE_HPP
5+
#define OPENCV_SIGNAL_SIGNAL_RESAMPLE_HPP
6+
7+
#include <opencv2/core.hpp>
8+
9+
namespace cv {
10+
namespace signal {
11+
12+
//! @addtogroup signal
13+
//! @{
14+
15+
/** @brief Signal resampling
16+
*
17+
* @param[in] inputSignal Array with input signal.
18+
* @param[out] outSignal Array with output signal
19+
* @param[in] inFreq Input signal frequency.
20+
* @param[in] outFreq Output signal frequency.
21+
* Signal resampling implemented a cubic interpolation function and a filtering function based on Kaiser window and Bessel function, used to construct a FIR filter.
22+
* Result is similar to `scipy.signal.resample`.
23+
24+
Detail: https://en.wikipedia.org/wiki/Sample-rate_conversion
25+
*/
26+
CV_EXPORTS_W void resampleSignal(InputArray inputSignal, OutputArray outSignal, const int inFreq, const int outFreq);
27+
28+
//! @}
29+
30+
}
31+
}
32+
#endif

modules/signal/perf/perf_main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
#include "perf_precomp.hpp"
5+
6+
CV_PERF_TEST_MAIN(signal)

modules/signal/perf/perf_precomp.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
#ifndef __OPENCV_PERF_PRECOMP_HPP__
5+
#define __OPENCV_PERF_PRECOMP_HPP__
6+
7+
#include "opencv2/ts.hpp"
8+
#include "opencv2/signal.hpp"
9+
10+
namespace opencv_test {
11+
using namespace perf;
12+
using namespace cv::signal;
13+
}
14+
15+
#endif

modules/signal/perf/perf_resample.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#include "perf_precomp.hpp"
6+
7+
using namespace std;
8+
using namespace cv;
9+
using namespace perf;
10+
11+
namespace opencv_test { namespace {
12+
13+
typedef TestBaseWithParam< tuple<uint32_t, uint32_t, uint32_t> > TestResampleFunc;
14+
15+
PERF_TEST_P( TestResampleFunc, resample_sin_signal,
16+
testing::Combine(
17+
testing::Values(1234U, 12345U, 123456U, 1234567U, 12345678U),
18+
testing::Values(16000U, 32000U, 44100U, 48000U),
19+
testing::Values(48000U, 44100U, 32000U, 16000U))
20+
)
21+
{
22+
uint32_t sample_signal_size = GET_PARAM(0);
23+
uint32_t inFreq = GET_PARAM(1);
24+
uint32_t outFreq = GET_PARAM(2);
25+
26+
Mat1f sample_signal(Size(sample_signal_size,1U));
27+
Mat1f outSignal(Size(1U, 1U));
28+
for (uint32_t i = 0U; i < (uint32_t)sample_signal.cols; ++i)
29+
{
30+
sample_signal.at<float>(0, i) = sinf(float(i));
31+
}
32+
declare.in(sample_signal).out(outSignal);
33+
TEST_CYCLE() resampleSignal(sample_signal, outSignal, inFreq, outFreq);
34+
SANITY_CHECK_NOTHING();
35+
}
36+
37+
}}

modules/signal/src/precomp.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html
4+
5+
#ifndef __OPENCV_SIGNAL_PRECOMP__
6+
#define __OPENCV_SIGNAL_PRECOMP__
7+
8+
#include <opencv2/core.hpp>
9+
10+
#endif

0 commit comments

Comments
 (0)