mirror of
https://github.com/metafy-social/python-scripts.git
synced 2025-01-18 07:17:03 +00:00
Project Added
This commit is contained in:
parent
4eda20bccd
commit
5beefdc50d
12
scripts/Detecting_objects_through_webcam/Readme.md
Normal file
12
scripts/Detecting_objects_through_webcam/Readme.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Detcting Objects Through Webcam of your device
|
||||
This program helps to detect any moving objects in the frame which further hepls us to understand if any object is moving out of the frame or not.
|
||||
|
||||
# Prerequisites
|
||||
Any System with a working webcam
|
||||
Any System having Python version 3 installed
|
||||
|
||||
# Dependencies
|
||||
Installed Pandas module
|
||||
Installed cv2 module
|
||||
Imported time module
|
||||
imported Datetime module
|
57
scripts/Detecting_objects_through_webcam/object_detector.py
Normal file
57
scripts/Detecting_objects_through_webcam/object_detector.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
import cv2
|
||||
import pandas
|
||||
|
||||
video=cv2.VideoCapture(0)
|
||||
first_frame=None
|
||||
status_list=[None,None]
|
||||
time=[]
|
||||
df=pandas.DataFrame(columns=["Start","End"])
|
||||
cnts= [[0,0], [255,0], [255,255], [0,255]]
|
||||
while True:
|
||||
check, frame = video.read()
|
||||
status=0
|
||||
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
|
||||
gray=cv2.GaussianBlur(gray,(21,21),0)
|
||||
if first_frame is None:
|
||||
first_frame=gray
|
||||
continue
|
||||
delta_frame=cv2.absdiff(first_frame,gray)
|
||||
thresh_data=cv2.threshold(delta_frame,30,255,cv2.THRESH_BINARY)[1]
|
||||
thresh_delta=cv2.dilate(thresh_data,None,iterations=5)
|
||||
(cnts,_) =cv2.findContours(thresh_data.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
|
||||
for contour in cnts:
|
||||
if cv2.contourArea(contour)<10000:
|
||||
continue
|
||||
status=1
|
||||
(x,y,w,h)=cv2.boundingRect(contour)
|
||||
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3)
|
||||
status_list.append(status)
|
||||
if status_list[-1]==1 and status_list[-2]==0:
|
||||
time.append(datetime.now())
|
||||
if status_list[-1]==0 and status_list[-2]==1:
|
||||
time.append(datetime.now())
|
||||
cv2.imshow("Capturing", gray)
|
||||
cv2.imshow("Delta Frame",delta_frame)
|
||||
cv2.imshow("Threshold Frame",thresh_data)
|
||||
cv2.imshow("Colour Frame",frame)
|
||||
|
||||
|
||||
key=cv2.waitKey(1)
|
||||
if key==ord('q'):
|
||||
if status==1:
|
||||
time.append(datetime.now())
|
||||
break
|
||||
|
||||
|
||||
print(time)
|
||||
for i in range(0,len(time),2):
|
||||
df=df.append({"Start":time[i],"End":time[i+1]},ignore_index=True)
|
||||
df.to_csv("Times.csv")
|
||||
|
||||
video.release()
|
||||
cv2.destroyAllWindows
|
||||
|
Loading…
Reference in New Issue
Block a user