Simple program to capture video using OpenCV and python for video inferencing

Note: OpenCV needs to be compiled and installed in Ubuntu to get all its full functionality. ‘pip install open-cv‘ will install python bindings but it is very limited by its use. Most of the time there are multiple issues while running. There are lot of dependencies for OpenCV build, I have installed OpenCV by following this tutorial for python 2.7 and python 3.5.  It took around two hours when compiled using 4 cores.

This program contains an infinite while loop, inside the loop each frame is captured from the video device specified and shows it frame by frame.

import cv2
#the video device number is 0
cap = cv2.VideoCapture(0)
    #reading frame
    ret, frame =
    #frame is displayed 
    #press q to break
    if cv2.waitKey(1) & 0xFF == ord('q'):

To run the program,


The earlier post is embedding this OpenCV program for video inferencing.