-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
motion detection with opencv and color extraction
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|