Skip to content

Instantly share code, notes, and snippets.

@ochilab
Created December 16, 2022 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochilab/51beaea1e17f0508b502efa6dccadce8 to your computer and use it in GitHub Desktop.
Save ochilab/51beaea1e17f0508b502efa6dccadce8 to your computer and use it in GitHub Desktop.
OpenCVで背景差分を取得する(Python編)
cap = cv2.VideoCapture("sample.avi")
subtractor = cv2.bgsegm.createBackgroundSubtractorMOG()
while True:
# 画像を取得
ret, frame = cap.read()
if not ret:
break
detect_mask = subtractor.apply(frame, learningRate=0)
#差分表示
cv2.imshow("detect_mask", detect_mask)
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment