This is an example of python usage.
10 cv2.ocl.setUseOpenCL(
False)
13 print (
"""BackgroundSubtractorCNT demo/benchmark/comparison 14 Usage: demo.py [params] 19 calculate also the background 21 use file (default is system camera) 23 run without GUI to measure times 25 bg subtraction type from - CNT/MOG2/KNN 28 def getBGSubtractor(typeStr):
30 return cv2.createBackgroundSubtractorKNN()
32 return cv2.createBackgroundSubtractorMOG2()
34 return bgsubcnt.createBackgroundSubtractor()
35 print (
"Unknown createBackgroundSubtractor type")
45 opts, args = getopt.getopt(argv,
"h", [
"help",
"bg",
"file=",
"nogui",
"type="])
46 except getopt.GetoptError:
51 if opt
in (
"-h",
"--help"):
58 elif opt ==
"--nogui":
64 cap = cv2.VideoCapture(filePath)
66 cap = cv2.VideoCapture(0)
68 if cap.isOpened() ==
False:
69 print (
"Could not initialize capturing...");
72 fgbg = getBGSubtractor(typeStr)
74 e1 = cv2.getTickCount()
76 ret, frame = cap.read()
78 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
81 cv2.imshow(
'Orig',frame)
84 bg = fgbg.getBackgroundImage()
89 ret, frame = cap.read()
91 e2 = cv2.getTickCount()
93 t = (e2 - e1)/cv2.getTickFrequency()
94 print (
"Execution took '%(val).3f' seconds." % {
'val': t});
98 cv2.destroyAllWindows()
100 if __name__ ==
"__main__":