I've been working on a project and have been kind of stumped after 6+ hours of googling and digging through openCV books.
import cv2
import numpy as np
cap = cv2.VideoCapture('tree.avi')
count = 0
x_pos = 0
y_pos = 0
a_x = 180
a_y = 180
frames = 60
if (cap.isOpened()== False):
print("Error opening video stream or file")
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
resized = frame
scale_percent = 200
width = int(frame.shape[1] * scale_percent / 100)
height = int(frame.shape[0] * scale_percent / 100)
dim = (width, height)
if count < 50 or count >= 55:
cv2.moveWindow('Frame', x_pos, y_pos)
cv2.imshow('Frame', frame)
if count in range(50, 55):
resized = cv2.resize(frame, dim, interpolation = cv2.INTER_AREA)
cv2.imshow('Frame',resized)
x_pos = x_pos + int((a_x / frames) * (count - 50))
y_pos = y_pos + int((a_y / frames) * (count - 50))
cv2.moveWindow('Frame', x_pos, y_pos)
count = count + 1
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
This is pretty generic code that I've taken as inspiration. What I want to achieve is to move the video window as it is playing to another location onscreen. I know from experience that simply adding another moveWindow() under the given one causes the window to fuzz between the two as it is applied to each frame.
Is there a way to perhaps make it so that, for example, frames 1~100 are at (100,100) and frames 101~200 are at (200, 200) and so on and so forth? Would be best if it's in real-time but any help regarding letting the user move the window while playing the video is very much appreciated.
Thanks in advance.
Update I found a way to manually set the video to move around for certain frames. However, this only seems to work for preset values. (ex) frames 50 ~ 55 Is there any way to use some external input in real-time?