Capturing Video From Camera
Often, we have to capture live stream with camera. OpenCV provides a very simple interface to this. Le us capture a video from the camera (I am using the in-built webcam of my laptop), display it.
To capture a video, we need to create a VideoCapture object. Its argument can be either the device index or the name of a video file. Device index is just the number to specify which camera. Normally one camera will be connected (as in my case). So we simply pass 0 (or -1). We can select the second camera by passing 1 and so on. After that, we can capture frame-by-frame. But at the end, don't forget to release the capture.
import numpy as np
def __init__(self, camera_key):
self.camera_key = camera_key
self.cap = cv2.VideoCapture(self.camera_key)
self.ret, self.frame = self.cap.read()
self.frame = cv2.flip(self.frame,180)
if cv2.waitKey(1) & 0xFF == ord('q'):
obj = Capture_Video(0)
if __name__ == "__main__":