commit 32703cb95c80817ffacd31545ada96bdcb268b7d
parent 566b1b3a44105e58fb408371e97be64e9b39596c
Author: Naveen Narayanan <zerous@nocebo.space>
Date: Sat, 8 Aug 2020 20:14:07 +0200
Detect center of contour and display it
Diffstat:
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/faldet.py b/faldet.py
@@ -1,5 +1,6 @@
import numpy as np
import cv2
+import imutils
# cap = cv2.VideoCapture('/home/zerous/src/video-fall-detection/queda.mp4')
cap = cv2.VideoCapture(0)
@@ -15,8 +16,16 @@ while(True):
avg = cv2.threshold(blur, 60, 255, cv2.THRESH_BINARY)[1]
contours, hierarchy = cv2.findContours(avg, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
- image = cv2.drawContours(frame, contours, -1, (0, 255, 0), 2)
- cv2.imshow('win1', image)
+ for c in contours:
+ M = cv2.moments(c)
+ image = cv2.drawContours(frame, contours, -1, (0, 255, 0), 2)
+ if M["m00"] != 0:
+ cX = int(M["m10"] / M["m00"])
+ cY = int(M["m01"] / M["m00"])
+ image = cv2.circle(image, (cX, cY), 7, (255, 255, 255), -1)
+ image = cv2.putText(image, "center", (cX - 20, cY - 20),
+ cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
+ cv2.imshow('win1', image)
k = cv2.waitKey(30) & 0xff
if k == 27: