Uncategorized

video editor – How to simplify repeated statements in python?


import cv2

import numpy as np

video1 = cv2.VideoCapture(‘c:/Media/Video/video.mp4’)

video2 = cv2.VideoCapture(‘c:/Media/Video/video.mp4’)

video3 = cv2.VideoCapture(‘c:/Media/Video/video.mp4’)

video4 = cv2.VideoCapture(‘c:/Media/Video/video.mp4’)

video5 = cv2.VideoCapture(‘c:/Media/Video/video.mp4’)

video6 = cv2.VideoCapture(‘c:/Media/Video/video.mp4’)

video7 = cv2.VideoCapture(‘c:/Media/Video/video.mp4’)

video8 = cv2.VideoCapture(‘c:/Media/Video/video.mp4’)

video9 = cv2.VideoCapture(‘c:/Media/Video/video.mp4’)

width = (int(video1.get(cv2.CAP_PROP_FRAME_WIDTH)))

height = (int(video1.get(cv2.CAP_PROP_FRAME_HEIGHT)))

while (video1.isOpened()):
ret1, frame1 = video1.read()

ret2, frame2 = video2.read()

ret3, frame3 = video3.read()

ret4, frame4 = video4.read()

ret5, frame5 = video5.read()

ret6, frame6 = video6.read()

ret7, frame7 = video7.read()

ret8, frame8 = video8.read()

ret9, frame9 = video9.read()



frame1 = cv2.resize(frame1, (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frame2 = cv2.resize(frame2, (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frame3 = cv2.resize(frame3, (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frame4 = cv2.resize(frame4, (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frame5 = cv2.resize(frame5, (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frame6 = cv2.resize(frame6, (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frame7 = cv2.resize(frame7, (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frame8 = cv2.resize(frame8, (int(width), int(height)), interpolation=cv2.INTER_CUBIC)
frame9 = cv2.resize(frame9, (int(width), int(height)), interpolation=cv2.INTER_CUBIC)



frameA = np.hstack((frame1, frame2, frame3))
frameB = np.hstack((frame4, frame5, frame6))
frameC = np.hstack((frame7, frame8, frame9))

resize1 = cv2.resize(frameA, (0,0), fx=0.5, fy=0.5)
resize2 = cv2.resize(frameB, (0,0), fx=0.5, fy=0.5)
resize3 = cv2.resize(frameC, (0,0), fx=0.5, fy=0.5)


cv2.imshow('tack', np.vstack([resize1, resize2, resize3]))
cv2.namedWindow('tack', cv2.WINDOW_NORMAL) 
cv2.moveWindow('tack', 45, 15)
print('123456789')
key = cv2.waitKey(24)
if int(key) == 32:
    break

video1.release()

video2.release()

video3.release()

video4.release()

video5.release()

video6.release()

video7.release()

video8.release()

video9.release()



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *