Contents of question

I have a question about what the program does.
I would like to make a difference between the background image and another image.

This siteI created a background subtraction program with reference to.bg_diff_path ='./diff.jpg'I'm not sure how to handle this, but if anyone can understand it, could you please tell me?fgmaskI somehow understood how to get the foreground of each image ...

Corresponding source code
import cv2
import numpy as np
import matplotlib.pyplot as plt
% matplotlib inline
img1 = cv2.imread ("reth-morclose-09393.jpg", 0)
img2 = cv2.imread ("reth-morclose-09944.jpg", 0)
fgbg = cv2.bgsegm.createBackgroundSubtractorMOG ()
fgmask = fgbg.apply (img1)
fgmask = fgbg.apply (img2)
bg_diff_path ='./diff.jpg'

cv2.imwrite (bg_diff_path, fgmask)
  • Answer # 1

    I want to do it

    Program processing content

    No one can explain it because only you can know it.
    (What do you want to do with the acquired foreground image?)

    If you want to know how to use BackgroundSubtractorMOG,
    There is a story about using this in the OpenCV tutorial, so why not read it?

    The content of the question is

    I'm not sure how to handle bg_diff_path ='./diff.jpg'

    It became a story, but
    Immediately after that, it becomes an argument of imwrite, so I think it is nothing but the image storage path.
    ("./" Is a description of the current position, so it will be saved as "diff.jpg" in the current directory.)