Ask Your Question

Volpe's profile - activity

2017-06-04 14:38:29 -0600 asked a question Changing the rate of updating background in a BackgroundSubtractor() function

Hello, i just want to know how to change the rate of updating the background model while using the cv2.BackgroundSubtactor() function ( Python language). In fact, I want to detect the mouvement of my hand, so i want to subtract it from the background, but the rate of updating the background is high, so my hand is considered quickly as part of the background and removed. What is the arguments of the BackgroundSubtraction function ? and how to deal with my issue ? my source code :

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

bgModel = cv2.createBackgroundSubtractorMOG2()


while True:
    ret, frame = cap.read()
    fgmask = bgModel.apply(frame)

    blur = cv2.medianBlur(fgmask, 5)
    res = cv2.bitwise_and(frame, frame, mask=fgmask)
    retval , thresh = cv2.threshold(blur,10,255,cv2.THRESH_BINARY)


    cv2.imshow('frame',thresh)
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()

Thanks for your help

2017-06-03 19:26:06 -0600 received badge  Editor (source)
2017-06-03 18:57:45 -0600 asked a question Background Subtraction

From a video, I want to subtract my hand from the static background,I used the function cv2.BackgroundSubtract(), but my problem is that my hand is mostly considered as part of the background, since it doesn't move much ( only the fingers moves) image description there's the source Code (i'm working with Python):

    import numpy as np
    import cv2

cap = cv2.VideoCapture(0)

bgModel = cv2.createBackgroundSubtractorMOG2()


while True:
    ret, frame = cap.read()
    fgmask = bgModel.apply(frame)

    #res = cv2.bitwise_and(frame, frame, mask=fgmask)

    cv2.imshow('frame',fgmask)
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()

Is there any other function that can do the job right ? I wanted to do a color skin recognition but I don't know how to do a Sampling Color directly from the video. Thanks for your Help