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) while(True): #reading frame ret, frame = cap.read() #frame is displayed cv2.imshow('window1',frame) #press q to break if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
To run the program,
#python2.7 python opencv_test.py #python3.5 python3 opencv_test.py
The earlier post is embedding this OpenCV program for video inferencing.