-
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.
- Loading branch information
0 parents
commit 8d2fe81
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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,35 @@ | ||
import cv2 as cv | ||
import numpy as np | ||
cap = cv.VideoCapture('movingball.mp4') | ||
kernel = np.ones((5,5),np.uint8) | ||
while(1): | ||
# Take each frame | ||
_, frame = cap.read() | ||
# Convert BGR to HSV | ||
hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV) | ||
|
||
# lower boundary RED color range values; Hue (0 - 20) | ||
lower1 = np.array([0, 100, 10]) | ||
upper1 = np.array([10, 255, 255]) | ||
|
||
# upper boundary RED color range values; Hue (160 - 180) | ||
lower2 = np.array([160,100,20]) | ||
upper2 = np.array([179,255,255]) | ||
|
||
lower_mask = cv.inRange(hsv, lower1, upper1) | ||
upper_mask = cv.inRange(hsv, lower2, upper2) | ||
|
||
full_mask = lower_mask + upper_mask; | ||
|
||
# Bitwise-AND mask and original image | ||
res = cv.bitwise_and(frame,frame, mask= full_mask) | ||
opening = cv.morphologyEx(res, cv.MORPH_OPEN, kernel) | ||
opAndClos = cv.morphologyEx(opening, cv.MORPH_CLOSE, kernel) | ||
|
||
cv.imshow('frame',frame) | ||
cv.imshow('mask',full_mask) | ||
cv.imshow('res',opAndClos) | ||
k = cv.waitKey(5) & 0xFF | ||
if k == 27: | ||
break | ||
cv.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,27 @@ | ||
import numpy as np | ||
import cv2 as cv | ||
from matplotlib import pyplot as plt | ||
|
||
img = cv.imread("/Users/nacia/Desktop/IMG_6123.jpg") | ||
assert img is not None, "nie ma pliku :(" | ||
|
||
b,g,r = cv.split(img) | ||
img = cv.merge((r,g,b)) | ||
|
||
cv.rectangle(img,(220,110),(165,50),(0,255,0),3) | ||
cv.rectangle(img,(220,110),(165,50),(0,255,0),3) | ||
cv.circle(img,(105,250),25,(0,0,255),-1) | ||
cv.circle(img,(297,255),20,(0,0,255),-1) | ||
|
||
#img[30:100,40:150,0:2] = 0 | ||
#bierzemy cały zakres składowych do : i składowej 2 -> (r,g,b) -> i przypisujemy jej 0 | ||
#0:2 -> wyrzucamy pierwsze 2 czyli zostaje tylko składowa b | ||
#[1,2] -> zostaje tylko 0 wiec r | ||
#[20:130,50:200] - obszar X i Y | ||
#[20:-1] -> od 20 do konca | ||
|
||
print(type(img)) | ||
print(img.shape) | ||
|
||
plt.imshow(img) | ||
plt.show() |
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,29 @@ | ||
import numpy as np | ||
import cv2 as cv | ||
|
||
cap = cv.VideoCapture(0) | ||
#0- kamera wbudowana 1- USB chyba | ||
|
||
if not cap.isOpened(): | ||
print('nie moge otworzyc kamery') | ||
exit() | ||
while True: | ||
#Capture fram-by-frame | ||
ret,frame = cap.read() | ||
#if frame is read correctly ret is True | ||
if not ret: | ||
print("cant recive frame") | ||
break | ||
#Our operations on the frame come here | ||
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY) | ||
color = cv.cvtColor(frame,1) | ||
|
||
#display the resulting frame | ||
cv.imshow('frame',gray) | ||
#imshow('frame',color) | ||
|
||
if cv.waitKey(1) == ord('q'): | ||
break | ||
#hen everything done | ||
cap.release() | ||
cv.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,22 @@ | ||
import cv2 as cv | ||
import numpy as np | ||
cap = cv.VideoCapture(0) | ||
while(1): | ||
# Take each frame | ||
_, frame = cap.read() | ||
# Convert BGR to HSV | ||
hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV) | ||
# define range of blue color in HSV | ||
lower_blue = np.array([110,50,50]) | ||
upper_blue = np.array([130,255,255]) | ||
# Threshold the HSV image to get only blue colors | ||
mask = cv.inRange(hsv, lower_blue, upper_blue) | ||
# Bitwise-AND mask and original image | ||
res = cv.bitwise_and(frame,frame, mask= mask) | ||
cv.imshow('frame',frame) | ||
cv.imshow('mask',mask) | ||
cv.imshow('res',res) | ||
k = cv.waitKey(5) & 0xFF | ||
if k == 27: | ||
break | ||
cv.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,22 @@ | ||
import cv2 as cv | ||
import numpy as np | ||
cap = cv.VideoCapture(0) | ||
while(1): | ||
# Take each frame | ||
_, frame = cap.read() | ||
# Convert BGR to HSV | ||
hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV) | ||
# define range of blue color in HSV | ||
lower_blue = np.array([0,10,10]) | ||
upper_blue = np.array([10,200,200]) | ||
# Threshold the HSV image to get only blue colors | ||
mask = cv.inRange(hsv, lower_blue, upper_blue) | ||
# Bitwise-AND mask and original image | ||
res = cv.bitwise_and(frame,frame, mask= mask) | ||
cv.imshow('frame',frame) | ||
cv.imshow('mask',mask) | ||
cv.imshow('res',res) | ||
k = cv.waitKey(5) & 0xFF | ||
if k == 27: | ||
break | ||
cv.destroyAllWindows() |