I am making a script in which you read a video file and detect and track object motion. I am loosely following this methodology: https://pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-python-and-opencv/
However, I don't want to run the code from a command window, I want it to work within spyder. This is a problem as at the end of the code, it displays the finished video using the cv2.imshow(frame) command, which instantly crashes spyder for some reason. To get around this, I am trying to use matplotlib instead, but I just can't get the frames to replace each other in one window (ie put the frames back together to form a video again).
This is the code I am using:
def cv2_imshow(a, **kwargs):
a = a.clip(0, 255).astype('uint8')
# cv2 stores colors as BGR; convert to RGB
if a.ndim == 3:
if a.shape[2] == 4:
a = cv2.cvtColor(a, cv2.COLOR_BGRA2RGBA)
else:
a = cv2.cvtColor(a, cv2.COLOR_BGR2RGB)
return plt.imshow(a, **kwargs)
get_ipython().run_line_magic('matplotlib', 'qt')
plt.ion()
cv2_imshow(frame)
What I end up with is basically a new window being created for each frame all over my screen (ie it is not a video in one window)
Does anyone have a way of doing this?
Essentially I want the process to be this: read video --> detect motion, create frame with threshold and frame with moving object in red box --> repeat over all frames, creating 3 videos (or even just the finished video with the movement detection)