Skip to content

AudioIO: add spectrogram samples for C++/python #20934

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

Merged
merged 5 commits into from
Dec 14, 2021

Conversation

SinM9
Copy link
Contributor

@SinM9 SinM9 commented Oct 24, 2021

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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

@SinM9 SinM9 force-pushed the spectrogram_samples branch from 50cf0fc to fce3b22 Compare November 15, 2021 11:14
@SinM9 SinM9 marked this pull request as ready for review November 15, 2021 11:45
author Sinitsina Maria <marusya19.09.99@gmail.com> 1635100993 +0300
committer Sinitsina Maria <marusya19.09.99@gmail.com> 1636985460 +0300

inital

update samples

fix warnings
@SinM9 SinM9 force-pushed the spectrogram_samples branch from fce3b22 to 0cf61d2 Compare November 15, 2021 14:19
@SinM9 SinM9 changed the title Spectrogram samples AudioIO: add spectrogram samples for C++/python Nov 15, 2021
@SinM9
Copy link
Contributor Author

SinM9 commented Nov 15, 2021

@allnes Check please

{
line(img, Point(i-1, static_cast<int>(reshape_audio[i-1])), Point(i, static_cast<int>(reshape_audio[i])), color, thickness);
}
resize(img, img, Size(cols, rows), INTER_AREA );
Copy link
Member

Choose a reason for hiding this comment

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

avoid "inplace" operations. There is performance src copy penalty.

"{inputType i | file | file or microphone }"
"{draw d | static | type of drawing: \n\t\t\tstatic - for plotting graph(s) across the entire input audio \n\t\t\tdynamic - for plotting graph(s) in a time-updating window}"
"{graph g | ampl_and_spec | type of graph: amplitude graph or/and spectrogram. Please use tags below : \n\t\t\tampl - draw the amplitude graph \n\t\t\tspec - draw the spectrogram\n\t\t\tampl_and_spec - draw the amplitude graph and spectrogram on one image under each other}"
"{audio a |../../../samples/data/Megamind.avi| name and path to file }"
Copy link
Member

Choose a reason for hiding this comment

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

Use cv.samples.findFile (Python) / samples::findFile (C++) instead of ../

cv.CAP_PROP_AUDIO_DATA_DEPTH, cv.CV_16S]
params = np.asarray(params)

cap.open(file, cv.CAP_MSMF, params)
Copy link
Member

Choose a reason for hiding this comment

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

cv.CAP_MSMF

This should be removed. We want to support other backends too.

Use CAP_ANY.

parser.add_argument("-g", "--graph", dest="graph", type=str, default="ampl_and_spec",
help="type of graph: amplitude graph or/and spectrogram. Please use tags below : ampl - draw the amplitude graph; spec - draw the spectrogram; ampl_and_spec - draw the amplitude graph and spectrogram on one image under each other")

parser.add_argument("-a", "--audio", dest="audio", type=str, default='../data/Megamind.avi',
Copy link
Member

Choose a reason for hiding this comment

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

../

need to be removed

@@ -0,0 +1,827 @@
import cv2 as cv
import numpy as np
Copy link
Member

Choose a reason for hiding this comment

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

Due to compatibility reasons numpy should go first (as a dependency)

}
else if (windowType == "Hamming")
{
double pi = 2 * acos(-1.0);
Copy link
Member

Choose a reason for hiding this comment

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

CV_PI, M_PI.

double pi = 2 * acos(-1.0);
for (int j = 1 - windLen; j < windLen; j+=2)
{
WindType.push_back(j * (0.53836 - 0.46164 * (cos(pi * j / (windLen - 1)))));
Copy link
Member

Choose a reason for hiding this comment

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

Please add link at Wiki article or other documents so reviewers can validate used expressions

Comment on lines 903 to 904
string grid = parser.get<string>("grid");
if ((grid != "on") && (grid != "off"))
Copy link
Member

Choose a reason for hiding this comment

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

get<bool>()


}

static bool checkArgs(CommandLineParser parser)
Copy link
Member

Choose a reason for hiding this comment

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

Input parameters should be passed as 'const reference'

if (cap.grab())
{
for (int nCh = 0; nCh < numberOfChannels; nCh++)
{
Copy link
Member

Choose a reason for hiding this comment

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

There is one imshow for multiple channels.

cap.open(0, CAP_MSMF, params);
if (!cap.isOpened())
{
cerr << "ERROR! Can't to open microphone" << endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

better:

cerr << "ERROR! Can't open microphone" << endl;

(w/o the "to")

@SinM9 SinM9 force-pushed the spectrogram_samples branch from a878ba1 to 6b23c8e Compare November 28, 2021 18:03
@@ -0,0 +1,1124 @@
#include <opencv2/core.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

Please rename samples: add audio_ prefix

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Well done! Thank you 👍

@alalek alalek merged commit d8b1fc4 into opencv:4.x Dec 14, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
AudioIO: add spectrogram samples for C++/python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants