how to get better human silhouettes from a video?
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()
You are doing the most basic form of background/foreground segmentation or background subtraction. Do a Google Scholar search with those terms to see how much more work you need to put in for high quality results.