Skip to content

Instantly share code, notes, and snippets.

@erogol
Last active May 25, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erogol/e35f58d7f94c9bf6540b0d9571c619a3 to your computer and use it in GitHub Desktop.
Save erogol/e35f58d7f94c9bf6540b0d9571c619a3 to your computer and use it in GitHub Desktop.
# thresholding difference frame for filling holes and noise reduction
# finding contours of moving regions
thresh = cv2.threshold(frameDelta, conf["delta_thresh"], 255,
cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations=2)
im2 ,cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
# loop over the contours
for c in cnts:
# if the contour is too small, ignore it
if cv2.contourArea(c) < conf["min_area"]:
continue
# compute the bounding box for the contour, draw it on the frame,
# and update the text
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
text = "Occupied"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment