forked from iamhimanshu0/opencv_projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
object Tracking and Detection by Color
- Loading branch information
1 parent
e989950
commit 8a38edc
Showing
1 changed file
with
53 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,53 @@ | ||
import cv2 as cv | ||
import numpy as np | ||
import imutils | ||
|
||
def main(): | ||
cap = cv.VideoCapture(0) | ||
|
||
|
||
if cap.isOpened(): | ||
ret , frame = cap.read() | ||
|
||
else: | ||
ret = False | ||
|
||
while ret: | ||
ret, frame = cap.read() | ||
frame = imutils.resize(frame, width=450) | ||
hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV) | ||
|
||
# blur range | ||
b_low = np.array([100,50,50]) | ||
b_high = np.array([140,255,255]) | ||
|
||
# green range | ||
sensitivity = 15; | ||
g_low = np.array([40, 100, 50]) | ||
g_high = np.array([100, 255, 255]) | ||
|
||
# red range | ||
r_low = np.array([170,25,20]) | ||
r_high = np.array([179,255,255]) | ||
|
||
# make mask | ||
img_mask_b = cv.inRange(hsv,b_low,b_high) | ||
img_mask_g = cv.inRange(hsv,g_low,g_high) | ||
img_mask_r = cv.inRange(hsv,r_low,r_high) | ||
# bitwise operation | ||
output_b = cv.bitwise_and(frame,frame,mask=img_mask_b) | ||
output_g = cv.bitwise_and(frame,frame,mask=img_mask_g) | ||
output_r = cv.bitwise_and(frame,frame,mask=img_mask_r) | ||
cv.imshow('blue',output_b) | ||
cv.imshow('green',output_g) | ||
cv.imshow('red',output_r) | ||
cv.imshow('original',frame) | ||
if cv.waitKey(1) == ord('q'): | ||
break | ||
|
||
cv.destroyAllWindows() | ||
cap.release() | ||
|
||
if __name__ == '__main__': | ||
main() | ||
|