Skip to content

Commit

Permalink
FIRST COMMIT FOR MOTION DETECTOR
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavrn committed Jul 15, 2019
1 parent 8ac1d54 commit cfe3577
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Binary file added ezgif.com-optimize.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions video_process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import numpy
import cv2,time

video=cv2.VideoCapture(0)
first_frame=None
a=0
while True:
a=a+1

check,frame=video.read()


print(check)
print(frame)
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
gray=cv2.GaussianBlur(gray,(21,21),0)
gray=cv2.GaussianBlur(gray,(21,21),0)
if first_frame is None:
first_frame=gray
continue
delta_frame=cv2.absdiff(first_frame,gray)
thrersh=cv2.threshold(delta_frame,30,255,cv2.THRESH_BINARY)[1]
#thrersh=cv2.dilate(thrersh,None,iterations=2)

(cnts,_)=cv2.findContours(thrersh.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)

for contour in cnts:
if cv2.contourArea(contour)<1000:
continue

(x,y,w,h)=cv2.boundingRect(contour)
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3)

cv2.imshow("thresh",thrersh)
cv2.imshow("blurres",gray)
cv2.imshow("delta frame",delta_frame)
cv2.imshow("color frame",frame)
key=cv2.waitKey(1)
if key==ord('q'):
break
print(a)
video.release()
cv2.destroyAllWindows()

0 comments on commit cfe3577

Please sign in to comment.