用matplotlib滑块重新计算

时间:2019-06-12 10:07:00

标签: python matplotlib

我想重新计算要在更改滑块时使用matplotlib显示的图像。我创建了一个示例代码,如下所示:

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
plt.imshow(disparity_map,'gray')

axMinDisparity = plt.axes([0.25, 0.0, 0.65, 0.03]) # (left, bottom, width, height)
axNumDisparities = plt.axes([0.25, 0.1, 0.65, 0.03])

saxMinDisparity = Slider(axMinDisparity, 'MinDisparity', -100, 100, valinit=defaults['numDisparities'], valstep=1)
saxNumDisparities = Slider(axNumDisparities, 'NumDisparities', 16, 192, valinit=defaults['numDisparities'], valstep=16)

def update(val):
    _minDisparity = int(saxMinDisparity.val)
    _numDisparities = int(saxNumDisparities.val)

    stereo = cv2.StereoSGBM_create(minDisparity= _minDisparity, 
        numDisparities = _numDisparities, 
        blockSize = 3, 
        uniquenessRatio = 5, 
        speckleWindowSize = 0, 
        speckleRange = 0, 
        disp12MaxDiff = -1, 
        P1 = 8*3*5**2, 
        P2 = 32*3*5**2, 
        preFilterCap = 63)
    disparity_map = stereo.compute(img_1_downsampled, img_2_downsampled)
    fig.canvas.draw()

saxMinDisparity.on_changed(update)
saxNumDisparities.on_changed(update)

plt.show()

我想每次滑块更改时都调用stereo.compute()函数。但是,图形窗口上显示的图像未更新。

0 个答案:

没有答案