Skip to content

Commit

Permalink
zaj 1 i 2 oraz proj 1 dodane
Browse files Browse the repository at this point in the history
  • Loading branch information
s22847 committed Mar 13, 2023
0 parents commit 8d2fe81
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added projekt1/movingball.mp4
Binary file not shown.
35 changes: 35 additions & 0 deletions projekt1/proj1.py
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()
27 changes: 27 additions & 0 deletions zaj1/test1.py
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()
29 changes: 29 additions & 0 deletions zaj1/test2.py
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()
22 changes: 22 additions & 0 deletions zaj2/test1.py
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()
22 changes: 22 additions & 0 deletions zaj2/test3.py
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()

0 comments on commit 8d2fe81

Please sign in to comment.