i'm trying to update three of the plots in my subplot. I think the problem is that the old image isn't cleared, so the new one is plotted on top of the old one..but i`m not really sure..maybe there is also another problem. But it's possible to plot a new image with cv2.imshow()...problem is that i need to plot multiple images in a subplot. How can i fix it ?
Depending on the position of the slider the mask is changing.
Thanks a lot!
img.fig2, img.ax2 = plt.subplots()
for i in range(3):
plt.subplot(2, 3, i + 1)
plt.imshow(img[i])
plt.xticks([])
plt.yticks([])
def update (val):
...........
for i in range(3):
res[i] = cv2.cvtColor(res[i], cv2.COLOR_HSV2RGB)
fig2 = plt.figure(2)
fig2.add_subplot(2, 3, 4 + i)
plt.imshow(res[i])
plt.xticks([])
plt.yticks([])
plt.draw()
plt.show()
whole code of interest:
fig2, ax2 = plt.subplots()
for i in range(3):
plt.subplot(2, 3, i + 1)
plt.imshow(img[i])
plt.xticks([])
plt.yticks([])
plt.pause(0.1)
def update(val):
hsv1 = cv2.cvtColor(img1, cv2.COLOR_BGR2HSV)
hsv2 = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV)
hsv3 = cv2.cvtColor(img3, cv2.COLOR_BGR2HSV)
l_b = np.array([shl.val, ssl.val, svl.val])
u_b = np.array([shu.val, ssu.val, svu.val])
mask1 = cv2.inRange(hsv1, l_b, u_b)
mask2 = cv2.inRange(hsv2, l_b, u_b)
mask3 = cv2.inRange(hsv3, l_b, u_b)
res1 = cv2.bitwise_and(img1, img1, mask=mask1)
res2 = cv2.bitwise_and(img2, img2, mask=mask2)
res3 = cv2.bitwise_and(img3, img3, mask=mask3)
res = [res1, res2, res3]
plt.clf()
for i in range(3):
res[i] = cv2.cvtColor(res[i], cv2.COLOR_HSV2RGB)
fig2 = plt.figure(2)
fig2.add_subplot(2, 3, 4 + i)
plt.imshow(res[i])
plt.xticks([])
plt.yticks([])
fig2.canvas.draw_idle()
plt.pause(0.01)
plt.draw_all()
shl.on_changed(update)
ssl.on_changed(update)
svl.on_changed(update)
shu.on_changed(update)
ssu.on_changed(update)
svu.on_changed(update)
plt.show()