i trying show 2 opencv video feeds in same figure subplots, couldn't find how it. when try using plt.imshow(...), plt.show()
, window won't appear. when try using cv2.imshow(...)
, shows 2 independent figures. want subplots :(. help?
here code have far:
import numpy np import cv2 import matplotlib.pyplot plt cap = cv2.videocapture(0) ret, frame = cap.read() while(true): ret, frame = cap.read() channels = cv2.split(frame) frame_merge = cv2.merge(channels) #~ subplot(211), plt.imshow(frame) #~ subplot(212), plt.imshow(frame_merged) cv2.imshow('frame',frame) cv2.imshow('frame merged', frame_merge) k = cv2.waitkey(30) & 0xff if k == 27: break cap.release() cv2.destroyallwindows()
update: ideally output should that:
you may use cv2.hconcat()
method horizontally join 2 images , display using imshow, keep in mind images must of same size , type applying hconcat
on them.
you may use vconcat
join images vertically.
import numpy np import cv2 import matplotlib.pyplot plt cap = cv2.videocapture(0) ret, frame = cap.read() bg = [[[0] * len(frame[0]) _ in xrange(len(frame))] _ in xrange(3)] while(true): ret, frame = cap.read() # resizing down image fit in screen. frame = cv2.resize(frame, none, fx = 0.5, fy = 0.5, interpolation = cv2.inter_cubic) # creating frame. channels = cv2.split(frame) frame_merge = cv2.merge(channels) # horizintally concatenating 2 frames. final_frame = cv2.hconcat((frame, frame_merge)) # show concatenated frame using imshow. cv2.imshow('frame',final_frame) k = cv2.waitkey(30) & 0xff if k == 27: break cap.release() cv2.destroyallwindows()