Skip to content

Project Added #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scripts/Detecting_objects_through_webcam/Readme.md
Original file line number Diff line number Diff line change
@@ -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 changes: 57 additions & 0 deletions scripts/Detecting_objects_through_webcam/object_detector.py
Original file line number Diff line number Diff line change
@@ -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