Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
motion detection  with opencv  and  color extraction
  • Loading branch information
redashu authored Jun 25, 2018
1 parent 3e704ac commit bc21122
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
28 changes: 28 additions & 0 deletions camera_red_capture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python

import cv2,time

# reading image
cap=cv2.VideoCapture(0)

while cap.isOpened():

# taking frames
status,frame=cap.read()
# extracting only red color
onlyred=cv2.inRange(frame,(0,0,0),(40,40,255))
print onlyred
onlygreen=cv2.inRange(frame,(0,0,0),(40,255,0))
#cv2.imshow('onlygreen',onlygreen)

if cv2.waitKey(1) & 0xFF == ord('q') :
break


cv2.destroyAllWindows()
cap.release()





10 changes: 10 additions & 0 deletions create_own_black.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/python

import numpy as np
import cv2

img=np.zeros((512,512))

cv2.imshow('balc',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
69 changes: 69 additions & 0 deletions motion_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/python

import cv2
# we are taking 3 frames
def imgdiff(x,y,z):
img1=cv2.absdiff(x,y)
img2=cv2.absdiff(y,z)
com_diff=cv2.bitwise_and(img1,img2)
return com_diff

cap=cv2.VideoCapture(0)
# taking 3 consistant frames
frame1=cap.read()[1]
frame2=cap.read()[1]
frame3=cap.read()[1]

# converting into grayscale
gray1=cv2.cvtColor(frame1,cv2.COLOR_BGR2GRAY)
gray2=cv2.cvtColor(frame2,cv2.COLOR_BGR2GRAY)
gray3=cv2.cvtColor(frame3,cv2.COLOR_BGR2GRAY)

while cap.isOpened():
# passing arg to above function
img_diff=imgdiff(gray1,gray2,gray3)
# showing diff
cv2.imshow('diffimg',img_diff)
# capturing new frames
status,frame=cap.read()
gray1=gray2
gray2=gray3
gray3=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)


if cv2.waitKey(1) & 0xFF == ord('q'):
break


cv2.destroyAllWindows()
cap.release()






























22 changes: 22 additions & 0 deletions red_color_extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python

import cv2,time

# reading image
img=cv2.imread('redhat.jpg')

# checking shape
print img.shape
time.sleep(5)
# printing data
print img

# extracting only red color
onlyred=cv2.inRange(img,(0,0,0),(40,40,255))
cv2.imshow('original',img)
cv2.imshow('onlyred',onlyred)

cv2.waitKey(0)

cv2.destroyAllWindows()

0 comments on commit bc21122

Please sign in to comment.