Things one should know/do to create a spectrogram [duplicate] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
For my current project in C++ / Qt I need a library (LGPL is preferred) which can calculate a spectrogram from a signal ( basically an array of doubles ). I already use Qwt for the GUI part.
Any suggestions?
Thanks.

It would be fairly easy to put together your own spectrogram. The steps are:
window function (fairly trivial,
e.g. Hanning)
FFT (FFTW would be
a good choice but if licensing is an
issue then go for Kiss FFT or
similar)
calculate log magnitude
of frequency domain components
(trivial: log(sqrt(re * re + im *
im))

"How do I create a frequency vs time plot?" lists several libraries, each of which can calculate a spectrogram from a signal.
Copied and pasted from my own answer:
Some source code to generate spectrograms / waterfall plots from audio data:
SoX - Sound eXchange includes spectrogram source code
Audacity includes spectrogram source code
glfer includes waterfall spectrum display spectrum source code
source code that uses fftw to compute the spectrogram of an audio stream
more source code that uses OpenAL and fftw to compute the spectrogram for an audio stream
"Sound Activated Recorder with Spectrogram in C#" by Jeff Morton
Topographica seems to include spectrogram source code
SpectroGraph for iTunes
Image to Spectrogram goes in the reverse direction from the above utilities.

you could use fftw (fftw.org) to calculate the spectrogram, you would still need to plot the data, but that should not be a problem

You can use FFT code from here. It uses C++ template metaprogramming for efficiency. The full source is provided by the author here.
It was suggested to include this code into Eigen for its use of templated (type friendly) code.

Related

Neural Network Image Classification, The Most Efficient Solution / Suggestion [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have already built a deep neural network image classifier program in Matlab (gives 1 output for each example, such as is it a car or not), using gradient descent and back propagation algorithms. It is a simple feed forward network, with 1 or 2 hidden layers. I'm using the obtained weights in a nvcc C++ for real time object detection.
NN training results have quite a good accuracy (more than %99.9, but not enough), and can process more than 100,000 image files of size 32x32. But only problem with the Matlab code is: it ends up in local minimums in each training, so requires many different trainings but its training speed is quite slow.
Other than my slowly working Matlab NN training code, I have tried:
1) OpenCV 3.0.0, it "probably" has a bug in virtual float cv::ml::StatModel::predict function at the moment. So I weren't able to use it properly.
2) Tried OpenNN with gui, but it even gets stuck during loading and training. I'm still working on to fix that.
3) Checked FANN, but could only find "one" tutorial code written in C++. May take quite a time for me to master it with out examples.
4) I had tried Theano in Python a few months ago, it was quite customizable, and has quite many tutorials. But had never tried training image files with it.
5) I can also transfer my Matlab code to nvcc C++, and try conjugate gradients method to speed up further. But didn't try this yet, it is the last choice for me.
Mastering in each path may take quite a big time, and I have many more different works to do too. Which path should I take, or do you have another suggestion? Thank you
If you have experience with Matlab, the easiest path is to go through the "VGG Convolutional Neural Networks Practical" and use their open source MatConvNet toolbox for Matlab: http://www.vlfeat.org/matconvnet/.

C++ image encode / decode library [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I'm developing a scientific application for image processing. It uses it's own simple data type for storing images (pixel data, number of channels, etc.). What I need is the ability to read images of common formats (bmp, jpeg, png, maybe others), convert to my internal format and then export them after processing back to one of common formats.
I want this app to be as lightweight, as possible so I don't want to include "heavy" libraries, such as OpenCV or ImageMagick just for this one purpose.
Is there any simple, light and efficient c++ library just for encoding and decoding images of popular formats? Or the only option I have is to use separate libs, such as libjpeg and libpng, for each format?
In order to open common formats, there are 2 ways: the separated libraries or, SOMETIMES, the operating system (you can open a JPEG with Windows API, for example).
There's no problem in using ImageMagick/OpenCV... they are very light! And even if you CONSIDER lighter to use the separated libraries, you will have to implement a common format of bitmap for you to obtain data from the output of each library (believe me, there are tricks here: number of channels, channels order, pixel order [from top-left to bottom-right], etc)... well, a lot of work!
So, why not use something already implemented like ImageMagick/OpenCV? All of this work is already done! I really believe this is a very good choice!
Use FreeImage.
FreeImage is an Open Source library project for developers who would like to support popular graphics image formats like PNG, BMP, JPEG, TIFF and others as needed by today's multimedia applications. FreeImage is easy to use, fast, multithreading safe, compatible with all 32-bit or 64-bit versions of Windows, and cross-platform (works both with Linux and Mac OS X).
to download: http://freeimage.sourceforge.net/

How to do Face Recognition using OpenCV? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am trying to do some Face Recognition (not detection) stuff using OpenCV. I found this article with some code:
http://www.cognotics.com/opencv/servo_2007_series/index.html
However, this code is written using the older C-style OpenCV API. Does someone have a C++ API version of this using a more recent version like OpenCV 2.3.1?
Update: OpenCV 2.4.2 now comes with the very new cv::FaceRecognizer. Please see the very detailed documentation at:
http://docs.opencv.org/trunk/modules/contrib/doc/facerec/index.html
I have released libfacerec, a modern face recognition library for the OpenCV C++ API (BSD license). libfacerec has no additional dependencies and implements the Eigenfaces method, Fisherfaces method and Local Binary Patterns Histograms. Parts of the library are going to be included in OpenCV 2.4.
The latest revision of the libfacerec is available at:
https://github.com/bytefish/libfacerec
The library was written for OpenCV 2.3.1 with the upcoming OpenCV 2.4 in mind, so I don't support OpenCV versions earlier than 2.3.1. This project comes as a CMake project with a well-documented API, there's also a tutorial on gender classification. You can see a HTML version of the documentation at:
http://www.bytefish.de/dev/libfacerec/
If you want to understand how those algorithms work, you might want to read my Guide To Face Recognition (includes Python and GNU Octave/MATLAB examples):
http://www.bytefish.de/blog/face_recognition_with_opencv2
The relevant publications are:
Turk, M., and Pentland, A. Eigenfaces for recognition.. Journal of Cognitive Neuroscience 3 (1991), 71–86.
Belhumeur, P. N., Hespanha, J., and Kriegman, D. Eigenfaces vs. Fisherfaces: Recognition using class specific linear projection.. IEEE Transactions on Pattern Analysis and Machine Intelligence 19, 7 (1997), 711–720.
Ahonen, T., Hadid, A., and Pietikainen, M. Face Recognition with Local Binary Patterns.. Computer Vision - ECCV 2004 (2004), 469–481.
I'm doing a face recognition project for my engineer's degree, using c++ api. I think that everything regarding face recognition in c++ is fairly straightforward, even simpler than in C (less pointers). To use PCA you have a class named PCA described here. Just use the proper methods and read documentation with understanding. To build the matrix with input data I've created a matrix of proper size, then pasted pictures as rows (use method reshape) into it (there is a method in cv::Mat that lets you to get easily a row of a matrix). You just need to keep sure that base data and tested data have the same parameters (channels, size,etc.)
EDIT:
using namespace cv; //somewhere near top
inserting data to data matrix:
62 Mat reshaped=img.reshape(1,1);
63 Mat dataRow=_data.row(y++);
64 resize(reshaped,dataRow,dataRow.size(),0,0,CV_INTER_LINEAR);
computing pca:
251 _pca(_data,Mat(),CV_PCA_DATA_AS_ROW); //compute pca
252 _pca.project(_data,_vectors); // project original data to new coordinates
As opencv's documentation isn't the best out there, it doesn't hurt to spend some time reading it. Most of the c api functions have their equivalents in c++ api, You only need to do some "write into search window and hit enter" searching. And, there are also tutorials in c++ to get a grip of the c++ api.

How to write C++ audio processing applications? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm an Electronics and Telecommunications student, next to my graduation. I'm gonna work on a project that involves my knowledge about DSP, music and audio in general. I allready know all the basic mathematic instruments and all the stuff I need to manage it, such as FFT, circular convolution ecc ecc.
I want to learn C++ programming basically for one reason: it's very important in the professional world!!! And I think it's one of the most used to write applications working with audio, especially when it's about real time processing.
Ok, after this small introduction I would like to know first, which are the most used libraries to work with audio processing in c++?? I was longer looking on the web but i couldn't find a lo of working stuff. (I work under linux with eclipse CDT enviroment).
Then I would like to know if there are good sources to learn how to write some working code, such as for example how to write a simple low pass filter. Basically now i will not write real time applications, I would like to start from the processing of a WAV file, or even better an MP3 file, so basically on vectors of samples.
Let's say that basically for now I would like to extract the waveform from an audio file, and save it to a thumbnail or to a PNG image.
Ok, for now I think it's all I would need.
Any ideas, advices, libraries, books, interesting sources about that?
Thanks a lot in advance for any kind of answer.
Giovanni.
I would suggest for you to write your own WAVE file reader and writer in C++, without relying on external libraries. The WAVE format is fairly straight forward, at least if you only intend on supporting the most common wave files.
Then you'll have access to the audio data, which you can easily manipulate in C++. I would recommend starting by modifying the volume, the number of channels to calculating statistics on the audio. Creating a PNG of the audio waveform requires some more advanced C++ skills...
Checkout this link which will give you some information on the available (commercial and open source) audio editing softwares.
Some interesting open source audio editing tools which are written in c++,
Audacity
LMMS
Qtractor
Ardour
Rosegarden
C++ library for audio processing.
SndObj
The Synthesis ToolKit in C++
C++ Code and links related Filters and audio processing..
C++ code for Filter,Audio Processing
Code Guru,Low pass filter
I've used BASS with good results (there's a C/C++ API you can use).

Scatter Plots in C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
What is the best way to graph scatter plots in C++?
Do you write data to a file and use another tool? Is there a library like matplotlib in Python?
I always write out data and then using gnuplot to create my graphs. It is by far the best way I have found of producing graphs in a variety of formats: eps, png, jpeg, xpm, you name it.
gnuplot will do scatter plot very easily. Provided the x and y values are in 2 space-separated columnss, then
plot "data.txt" using 1:2
Will give you a quick scatter plot. Then you can adjust it and what not using other gnuplot commands.
If you are involved in sciences, then learning gnuplot will be very valuable to you. It kicks the crap out of doing excel plots for sure and it eases the task of making plots to include in papers.
If you are looking for a C++ library rather than I independent plotting tool like gnuplot, I would consider the following:
Koolplot
dislin (Wikipedia article on dislin)
dislin seems to be the more interesting of the two. Here is a description extracted from the wikipedia article:
DISLIN is a high-level and easy to use plotting library developed by Helmut Michels at the Max Planck Institute in Katlenburg-Lindau, Germany. Helmut Michels currently works as a mathematician and Unix system manager at the computer center of the institute.
The DISLIN library contains routines and functions for displaying data as curves, bar graphs, pie charts, 3D-colour plots, surfaces, contours and maps. Several output formats are supported such as X11, VGA, PostScript, PDF, CGM, HPGL, SVG, PNG, BMP, PPM, GIF and TIFF.
DISLIN is available for the programming languages Fortran 77, Fortran 90/95 and C. Plotting extensions for the languages Perl, Python and Java are also supported for most operating systems. The current version of DISLIN is 9.4, released in October 2008. The first version 1.0 was released in December 1986.
The DISLIN software is free for non-commercial use.
Very heavy solution: you could link against ROOT, which will do just about anything you want:
runs on Mac, Windows and Linux
runs compiled or using the cint interperter
output to a file in encapsulated postscript, PDF, gif, png...
display to the screen using several different technologies
serialize the data in an internal format that can be manipulated later
Sure, its a bit much for most people, but it does do exactly what you asked for. I use it because I know it and it is already on my machines becase I'm that kind of physicist.
Good old GNU, they have everything...
http://directory.fsf.org/project/plotutils/
This is certainly not the best way but I usually write output files that can be read by R and use this, along with an appropriate script, to plot the graphs.
The problem here is that C++, unlike Java for example, does not have built-in GUI or graphics. If you want to generate graphs with C++ you would need to use a GUI library available for your OS. There are free GUI libraries, many cross-plaform such as Qt or GTK.
However, as other people have pointed out, the easiest thing for you to do would be to save the data into a text file, and use another program to generate the graph. gnuplot is definitely a good choice. It comes standard with most linux distros, and you get for Windows under cygwin.
Regards plotting in C++ for anyone who didn't do it yet. I will say what I did to plot Graphs in C++
Download the zipped file "gp443win32.zip" from http://sourceforge.jp/projects/sfnet_gnuplot/downloads/gnuplot/4.4.3/gp443win32.zip/
Extract it in "C:\Gnuplot"
then I read "C:\Gnuplot\gnuplot\README.Windows"
and I got these information:
I used Windows 7 ==> so you need to download "winhlp32.exe"... just search for it "winhlp32.exe Windows 7" in a search engine and go through the first link.
Append to the "Path" Environment variable the path for binary folder which is "C:\Gnuplot\gnuplot\binary"
then I shutdown my computer and open it again. After I found that it didn't sense the change in the environment variables :D
you need now to write a sample code to test your plotting ability :)
so you can visit this link
http://code.google.com/p/gnuplot-cpp/source/browse/#svn%2Ftrunk
to see the header file "gnuplot_i.hpp" and source file "example.cc".
You will get many and many graphs, choose your appropriate graph, customize your core, and enjoy :)
If you're familiar with matplotlib, you can embed python in C/C++ applications. Depending on what you want it for, this might be a quick solution.
Chart Director has bindings for C++. I've used their .Net libraries, and I've been pretty happy with them. It's a pretty cheap library, and gives you the power to do all sorts of different charts.