AudioIO: add spectrogram samples for C++/python#20934
Conversation
50cf0fc to
fce3b22
Compare
fce3b22 to
0cf61d2
Compare
|
@allnes Check please |
samples/cpp/spectrogram.cpp
Outdated
| { | ||
| 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 ); |
There was a problem hiding this comment.
avoid "inplace" operations. There is performance src copy penalty.
samples/cpp/spectrogram.cpp
Outdated
| "{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 }" |
There was a problem hiding this comment.
Use cv.samples.findFile (Python) / samples::findFile (C++) instead of ../
samples/python/spectrogram.py
Outdated
| cv.CAP_PROP_AUDIO_DATA_DEPTH, cv.CV_16S] | ||
| params = np.asarray(params) | ||
|
|
||
| cap.open(file, cv.CAP_MSMF, params) |
There was a problem hiding this comment.
cv.CAP_MSMF
This should be removed. We want to support other backends too.
Use CAP_ANY.
samples/python/spectrogram.py
Outdated
| 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', |
samples/python/spectrogram.py
Outdated
| @@ -0,0 +1,827 @@ | |||
| import cv2 as cv | |||
| import numpy as np | |||
There was a problem hiding this comment.
Due to compatibility reasons numpy should go first (as a dependency)
samples/cpp/spectrogram.cpp
Outdated
| } | ||
| else if (windowType == "Hamming") | ||
| { | ||
| double pi = 2 * acos(-1.0); |
samples/cpp/spectrogram.cpp
Outdated
| 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))))); |
There was a problem hiding this comment.
Please add link at Wiki article or other documents so reviewers can validate used expressions
samples/cpp/spectrogram.cpp
Outdated
| string grid = parser.get<string>("grid"); | ||
| if ((grid != "on") && (grid != "off")) |
samples/cpp/spectrogram.cpp
Outdated
|
|
||
| } | ||
|
|
||
| static bool checkArgs(CommandLineParser parser) |
There was a problem hiding this comment.
Input parameters should be passed as 'const reference'
samples/cpp/spectrogram.cpp
Outdated
| if (cap.grab()) | ||
| { | ||
| for (int nCh = 0; nCh < numberOfChannels; nCh++) | ||
| { |
There was a problem hiding this comment.
There is one imshow for multiple channels.
samples/cpp/spectrogram.cpp
Outdated
| cap.open(0, CAP_MSMF, params); | ||
| if (!cap.isOpened()) | ||
| { | ||
| cerr << "ERROR! Can't to open microphone" << endl; |
There was a problem hiding this comment.
better:
cerr << "ERROR! Can't open microphone" << endl;
(w/o the "to")
a878ba1 to
6b23c8e
Compare
samples/cpp/spectrogram.cpp
Outdated
| @@ -0,0 +1,1124 @@ | |||
| #include <opencv2/core.hpp> | |||
There was a problem hiding this comment.
Please rename samples: add audio_ prefix
AudioIO: add spectrogram samples for C++/python
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.