The other day I tried to input a video using opencv and display it. The environment was done on macOS Catalina vs Code, but at that time
zsh: abort python load_video.py
Was displayed, and a phenomenon occurred in which processing stopped. From the point of view of the conclusion, I found that it is necessary to get permission for the camera by hitting ** directly on the terminal instead of hitting the command on VScode. Reference
I'm currently looking for a way to do it well on VScode. The detailed code is shown below for reference. * * * mp4 file and camera referring to openCV tutorial page The code for displaying the video is shown below.
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
You can also display videos by setting the argument of cv2.VideoCapture () to any video directory.
Recommended Posts