1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

python: 'cv2.' -> 'cv.' via 'import cv2 as cv'

This commit is contained in:
Alexander Alekhin
2017-12-11 12:55:03 +03:00
parent 9665dde678
commit 5560db73bf
162 changed files with 2083 additions and 2084 deletions
@@ -37,31 +37,31 @@ the time proportions that those colours stay in the scene. The probable backgrou
ones which stay longer and more static.
While coding, we need to create a background object using the function,
**cv2.createBackgroundSubtractorMOG()**. It has some optional parameters like length of history,
**cv.createBackgroundSubtractorMOG()**. It has some optional parameters like length of history,
number of gaussian mixtures, threshold etc. It is all set to some default values. Then inside the
video loop, use backgroundsubtractor.apply() method to get the foreground mask.
See a simple example below:
@code{.py}
import numpy as np
import cv2
import cv2 as cv
cap = cv2.VideoCapture('vtest.avi')
cap = cv.VideoCapture('vtest.avi')
fgbg = cv2.createBackgroundSubtractorMOG()
fgbg = cv.createBackgroundSubtractorMOG()
while(1):
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
cv2.imshow('frame',fgmask)
k = cv2.waitKey(30) & 0xff
cv.imshow('frame',fgmask)
k = cv.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
cv.destroyAllWindows()
@endcode
( All the results are shown at the end for comparison).
@@ -80,24 +80,24 @@ detecting shadows or not. If detectShadows = True (which is so by default), it
detects and marks shadows, but decreases the speed. Shadows will be marked in gray color.
@code{.py}
import numpy as np
import cv2
import cv2 as cv
cap = cv2.VideoCapture('vtest.avi')
cap = cv.VideoCapture('vtest.avi')
fgbg = cv2.createBackgroundSubtractorMOG2()
fgbg = cv.createBackgroundSubtractorMOG2()
while(1):
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
cv2.imshow('frame',fgmask)
k = cv2.waitKey(30) & 0xff
cv.imshow('frame',fgmask)
k = cv.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
cv.destroyAllWindows()
@endcode
(Results given at the end)
@@ -120,26 +120,26 @@ frames.
It would be better to apply morphological opening to the result to remove the noises.
@code{.py}
import numpy as np
import cv2
import cv2 as cv
cap = cv2.VideoCapture('vtest.avi')
cap = cv.VideoCapture('vtest.avi')
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))
fgbg = cv2.createBackgroundSubtractorGMG()
kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE,(3,3))
fgbg = cv.createBackgroundSubtractorGMG()
while(1):
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
fgmask = cv2.morphologyEx(fgmask, cv2.MORPH_OPEN, kernel)
fgmask = cv.morphologyEx(fgmask, cv.MORPH_OPEN, kernel)
cv2.imshow('frame',fgmask)
k = cv2.waitKey(30) & 0xff
cv.imshow('frame',fgmask)
k = cv.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
cv.destroyAllWindows()
@endcode
Results
-------