Я нашел этот код из https://www.pyimagesearch.com/2015/06/01/home-surveillance-and-motion-detection-with-the-raspberry-pi-python-and-opencv/
Это прекрасно работает .
Но я отмечаю, что он обнаруживает, что 2 человека приближаются или держатся за руки как один человек .
Люди рядом в одном и том же окружающем ящике
Как их разделить?
# ---- Image from video
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21, 21), 0)
# if the average frame is None, initialize it
if average is None:
print("[INFO] starting background model...")
average = gray.copy().astype("float")
return 0, image
# accumulate the weighted average between the current frame and
# previous frames, then compute the difference between the current
# frame and running average
cv2.accumulateWeighted(gray, average, 0.5)
frame_delta = cv2.absdiff(gray, cv2.convertScaleAbs(average))
# threshold the delta image, dilate the thresholded image to fill
# in holes, then find contours on thresholded image
thresh = cv2.threshold(frame_delta, var_sis.config["delta_thresh"], 255,
cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations=2)
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
sorted contours = sorted(cnts, key=lambda x: cv2.contourArea(x), reverse=True)
# -----> I got contourns