Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 06c7f85

Browse files
Merge pull request avinashkranjan#1600 from Tanya-1109/fixex
Added necessary files
2 parents c1491ff + da00d6c commit 06c7f85

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Face-Detection-using-OpenCV
2+
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.
3+
4+
# Prerequisites
5+
Any System with a working webcam
6+
Any System having Python version 3 installed
7+
8+
# Dependencies
9+
Installed Pandas module
10+
Installed cv2 module
11+
Imported time module
12+
imported Datetime module
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
import time
3+
from datetime import datetime
4+
5+
import cv2
6+
import pandas
7+
8+
video=cv2.VideoCapture(0)
9+
first_frame=None
10+
status_list=[None,None]
11+
time=[]
12+
df=pandas.DataFrame(columns=["Start","End"])
13+
cnts= [[0,0], [255,0], [255,255], [0,255]]
14+
while True:
15+
check, frame = video.read()
16+
status=0
17+
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
18+
gray=cv2.GaussianBlur(gray,(21,21),0)
19+
if first_frame is None:
20+
first_frame=gray
21+
continue
22+
delta_frame=cv2.absdiff(first_frame,gray)
23+
thresh_data=cv2.threshold(delta_frame,30,255,cv2.THRESH_BINARY)[1]
24+
thresh_delta=cv2.dilate(thresh_data,None,iterations=5)
25+
(cnts,_) =cv2.findContours(thresh_data.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
26+
for contour in cnts:
27+
if cv2.contourArea(contour)<10000:
28+
continue
29+
status=1
30+
(x,y,w,h)=cv2.boundingRect(contour)
31+
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3)
32+
status_list.append(status)
33+
if status_list[-1]==1 and status_list[-2]==0:
34+
time.append(datetime.now())
35+
if status_list[-1]==0 and status_list[-2]==1:
36+
time.append(datetime.now())
37+
cv2.imshow("Capturing", gray)
38+
cv2.imshow("Delta Frame",delta_frame)
39+
cv2.imshow("Threshold Frame",thresh_data)
40+
cv2.imshow("Colour Frame",frame)
41+
42+
43+
key=cv2.waitKey(1)
44+
if key==ord('q'):
45+
if status==1:
46+
time.append(datetime.now())
47+
break
48+
49+
50+
print(time)
51+
for i in range(0,len(time),2):
52+
df=df.append({"Start":time[i],"End":time[i+1]},ignore_index=True)
53+
df.to_csv("Times.csv")
54+
55+
video.release()
56+
cv2.destroyAllWindows
57+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /