0
我有以下代码创建的音频文件的波形:提取RGBA阵列matplotlib
times = np.arange(len(data))/float(samplerate)
fig = plot.figure(figsize = (8,4), frameon = False)
axes = fig.gca()
if(channels == 1): #mono file
axes.fill_between(times, data, color = 'k')
else: #stereo file
axes.fill_between(times, data[:,0], data[:,1], color = 'k')
plot.savefig(savefile, dpi = 'figure', transparent = True)
我曾尝试多种方法提取从该图然而没有RGBA阵列获得了成功。我当前的代码是下面:
canvas.draw() # draw the canvas, cache the renderer
width, height = fig.get_size_inches() * fig.get_dpi()
waveformRGBA= np.fromstring(canvas.tostring_rgb(),dtype='uint8').reshape(height, width, 3)
print waveformRGBA
这种方法产生的[255,255,255]
任何想法空白RGBA阵列???
您的“当前代码”不显示如何创建“画布”。这可能有助于了解。 –
可能重复的[matplotlib:渲染到缓冲区/访问像素数据](http://stackoverflow.com/questions/21939658/matplotlib-render-into-buffer-access-pixel-data) – kazemakase
我看到你使用差不多(但不完全)与在上面链接的问题的答案中相同的命令。这个答案中的例子是否也适用于你?否则,尝试解决这些差异。 – kazemakase