Skip to content

Commit

Permalink
added signal module
Browse files Browse the repository at this point in the history
  • Loading branch information
a.mishutin committed Jan 9, 2024
1 parent c7602a8 commit 68a4b7b
Show file tree
Hide file tree
Showing 13 changed files with 686 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ $ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -D BUILD_opencv_<r

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

- **signal**: Signal processing algorithms

- **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.

- **shape**: Shape Distance and Matching
Expand Down
2 changes: 2 additions & 0 deletions modules/signal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(the_description "Signal processing algorithms")
ocv_define_module(signal opencv_core WRAP python)
4 changes: 4 additions & 0 deletions modules/signal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Signal Processing algorithms
================================================

Signal resampling done with cubic interpolation and low-pass filtering
10 changes: 10 additions & 0 deletions modules/signal/include/opencv2/signal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#ifndef OPENCV_SIGNAL_HPP
#define OPENCV_SIGNAL_HPP

#include "opencv2/core.hpp"
#include "opencv2/signal/signal_resample.hpp"

#endif
32 changes: 32 additions & 0 deletions modules/signal/include/opencv2/signal/signal_resample.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#ifndef OPENCV_SIGNAL_SIGNAL_RESAMPLE_HPP
#define OPENCV_SIGNAL_SIGNAL_RESAMPLE_HPP

#include <opencv2/core.hpp>

namespace cv {
namespace signal {

//! @addtogroup signal
//! @{

/** @brief Signal resampling
*
* @param[in] inputSignal Array with input signal.
* @param[out] outSignal Array with output signal
* @param[in] inFreq Input signal frequency.
* @param[in] outFreq Output signal frequency.
* Signal resampling implemented a cubic interpolation function and a filtering function based on Kaiser window and Bessel function, used to construct a FIR filter.
* Result is similar to `scipy.signal.resample`.
Detail: https://en.wikipedia.org/wiki/Sample-rate_conversion
*/
CV_EXPORTS_W void resampleSignal(InputArray inputSignal, OutputArray outSignal, const int inFreq, const int outFreq);

//! @}

}
}
#endif
6 changes: 6 additions & 0 deletions modules/signal/perf/perf_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"

CV_PERF_TEST_MAIN(signal)
15 changes: 15 additions & 0 deletions modules/signal/perf/perf_precomp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef __OPENCV_PERF_PRECOMP_HPP__
#define __OPENCV_PERF_PRECOMP_HPP__

#include "opencv2/ts.hpp"
#include "opencv2/signal.hpp"

namespace opencv_test {
using namespace perf;
using namespace cv::signal;
}

#endif
37 changes: 37 additions & 0 deletions modules/signal/perf/perf_resample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#include "perf_precomp.hpp"

using namespace std;
using namespace cv;
using namespace perf;

namespace opencv_test { namespace {

typedef TestBaseWithParam< tuple<uint32_t, uint32_t, uint32_t> > TestResampleFunc;

PERF_TEST_P( TestResampleFunc, resample_sin_signal,
testing::Combine(
testing::Values(1234U, 12345U, 123456U, 1234567U, 12345678U),
testing::Values(16000U, 32000U, 44100U, 48000U),
testing::Values(48000U, 44100U, 32000U, 16000U))
)
{
uint32_t sample_signal_size = GET_PARAM(0);
uint32_t inFreq = GET_PARAM(1);
uint32_t outFreq = GET_PARAM(2);

Mat1f sample_signal(Size(sample_signal_size,1U));
Mat1f outSignal(Size(1U, 1U));
for (uint32_t i = 0U; i < (uint32_t)sample_signal.cols; ++i)
{
sample_signal.at<float>(0, i) = sinf(float(i));
}
declare.in(sample_signal).out(outSignal);
TEST_CYCLE() resampleSignal(sample_signal, outSignal, inFreq, outFreq);
SANITY_CHECK_NOTHING();
}

}}
10 changes: 10 additions & 0 deletions modules/signal/src/precomp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html

#ifndef __OPENCV_SIGNAL_PRECOMP__
#define __OPENCV_SIGNAL_PRECOMP__

#include <opencv2/core.hpp>

#endif
Loading

0 comments on commit 68a4b7b

Please sign in to comment.