Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is there any way to get better human silhouettes?

I would like to get the human silhouettes from the video. But the silhouettes I got are not good enough. I have tried the following code. I would appreciate if you have any advice for me. Thanks

cap = cv2.VideoCapture(pathIn)
success ,frame = cap.read()
_, first_frame = cap.read()
first_gray = cv2.cvtColor(first_frame, cv2.COLOR_BGR2GRAY)
first_gray = cv2.GaussianBlur(first_gray, (5, 5), 0)
count = 0
while True:
    count = 0
    success, frame = cap.read()
    if not success:
        break
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray_frame = cv2.GaussianBlur(gray_frame, (5, 5), 0)

    difference = cv2.absdiff(first_gray, gray_frame)
    _, difference = cv2.threshold(difference, 25, 255, cv2.THRESH_BINARY_INV)

    cv2.imshow("First frame", first_frame)
    cv2.imwrite(os.path.join(img_dir,"frame{:d}.jpg".format(count)),difference)
    cv2.imshow("gray_Frame", gray_frame)
    cv2.imshow("difference", difference)

    if cv2.waitKey(1) & 0xFF == ord("q"):
        break
    count = count  + 1 
cap.release()
cv2.destroyAllWindows()

Is there any way to get better human silhouettes?

I would like to get the human silhouettes from the video. But the silhouettes I got are not good enough. I have tried the following code. I would appreciate if you have any advice for me. Thanks

cap = cv2.VideoCapture(pathIn)
success ,frame = cap.read()
_, first_frame = cap.read()
first_gray = cv2.cvtColor(first_frame, cv2.COLOR_BGR2GRAY)
first_gray = cv2.GaussianBlur(first_gray, (5, 5), 0)
count = 0
while True:
    count = 0
    success, frame = cap.read()
    if not success:
        break
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray_frame = cv2.GaussianBlur(gray_frame, (5, 5), 0)

    difference = cv2.absdiff(first_gray, gray_frame)
    _, difference = cv2.threshold(difference, 25, 255, cv2.THRESH_BINARY_INV)

    cv2.imshow("First frame", first_frame)
    cv2.imwrite(os.path.join(img_dir,"frame{:d}.jpg".format(count)),difference)
    cv2.imshow("gray_Frame", gray_frame)
    cv2.imshow("difference", difference)

    if cv2.waitKey(1) & 0xFF == ord("q"):
        break
    count = count  + 1 
cap.release()
cv2.destroyAllWindows()