I've been programming in python for a few weeks...
I work with industrial automation and in my work
I don't have a development environment for python available, so I use colab
the code below was used for me to run video by cv2
I hope I helped someone
import cv2
from google.colab.patches import cv2_imshow
import time
cap = cv2.VideoCapture('video.mp4')
while cap.isOpened():
#while True:
ok, frame = cap.read()
if not ok:
break
if ok:
#edit your video size here, to adjust the performance
largura=frame.shape[1]
altura=frame.shape[0]
lamenor=int(frame.shape[1]/5)
altmenor=int(frame.shape[0]/5)
frame = cv2.resize(frame, (lamenor,altmenor))
# as you read
clear_output(wait=True)
cv2_imshow(frame)
#delay time to update frame
time.sleep(1.1)
if cv2.waitKey(1100) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
...
Edited...
Modified part to make it more fun if you change the source to a webcam
Original:
cap = cv2.VideoCapture('video.mp4')
Modified:
#0 = webcam position in your webcams
cap = cv2.VideoCapture(0)
#or cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
And this part for flip/mirror the frame:
frame2 = cv2.flip(frame, 1)
# as you read
clear_output(wait=True)
cv2_imshow(frame)
cv2_imshow(frame2)