python提取图片频谱,如何从频谱图中提取频率?

import cv2

import matplotlib.pyplot as plt

import sys

sys.path.append('/usr/local/lib/python2.7/site-packages')

import glob, os

import numpy as np

import wave from scipy.io

import wavfile

import time

results_dir = "/home/undead/Documents/MetricTestFolder/"

for root, dirs, files in os.walk("/home/undead/ShareWindowsDesktop/SampleWavs"): #LOADS SONGS FROM DIRECTORY

for file in files:

if file.endswith(".wav"):

filepath = os.path.join(root, file)

fs, frames = wavfile.read(filepath)

channels = [

np.array(frames[:, 0]),

np.array(frames[:, 1])

]

fig, (ax2) = plt.subplots(nrows=1)

data, freqs, bins, im = ax2.specgram(channels[0], NFFT=8192, Fs=44100, noverlap=int(8192 * 0.75))

start = time.time()

ax2.pcolormesh(bins, freqs, 10. * np.log10(data))

ax2.axis('tight')

plt.axis('off')

plt.subplots_adjust(left=0.0, right=1.0, bottom=0.0, top=1.0)

plt.xlim([0, 250])

plt.ylim([0, 15000])

plt.savefig(results_dir + "%s.png" % os.path.splitext(file)[0], dpi=450)

plt.close("all")

endt = time.time()

print "%f" % (endt - start)

#end

你可能感兴趣的:(python提取图片频谱)