Testing exercises working
This commit is contained in:
commit
568ebfec97
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Current File",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
}
|
||||
]
|
||||
}
|
9
example/ex1 - showImg.py
Normal file
9
example/ex1 - showImg.py
Normal file
@ -0,0 +1,9 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import os
|
||||
|
||||
# Load an color image in grayscale
|
||||
img = cv2.imread(os.path.join(os.getcwd(), './res/balls.png'),0)
|
||||
cv2.imshow('image',img)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
45
example/ex2 - showChannels.py
Normal file
45
example/ex2 - showChannels.py
Normal file
@ -0,0 +1,45 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import copy
|
||||
|
||||
image = cv2.imread('./res/balls.png')
|
||||
|
||||
if image is None:
|
||||
print("\nERROR: Could not open image\n")
|
||||
exit()
|
||||
|
||||
# Bepaal afmetingen en aantal kleurkanalen
|
||||
height = image.shape[0]
|
||||
width = image.shape[1]
|
||||
colors = image.shape[2]
|
||||
print ("%d pixels breed" % width)
|
||||
print ("%d pixels hoog" % height)
|
||||
print ("%d kleur kanalen" % colors)
|
||||
image_RGB = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
image_HSV = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
|
||||
image_RGB = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
|
||||
#RGB - Blue
|
||||
cv2.imshow('B-RGB',image_RGB[:, :, 0])
|
||||
|
||||
# RGB - Green
|
||||
cv2.imshow('G-RGB',image_RGB[:, :, 1])
|
||||
|
||||
# RGB Red
|
||||
cv2.imshow('R-RGB',image_RGB[:, :, 2])
|
||||
|
||||
# HSV - H
|
||||
cv2.imshow('H-HSV',image_HSV[:, :, 0])
|
||||
|
||||
# HSV - S
|
||||
cv2.imshow('S-HSV',image_HSV[:, :, 1])
|
||||
|
||||
# HSV - V
|
||||
cv2.imshow('V-HSV',image_HSV[:, :, 2])
|
||||
|
||||
cv2.imshow("HSV", image_HSV)
|
||||
cv2.imshow("RGB", image_RGB)
|
||||
cv2.imshow("Input image", image)
|
||||
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
21
example/ex3 - showCamera.py
Normal file
21
example/ex3 - showCamera.py
Normal file
@ -0,0 +1,21 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
cap = cv2.VideoCapture(0)
|
||||
|
||||
while(True):
|
||||
# Capture frame-by-frame
|
||||
ret, frame = cap.read()
|
||||
|
||||
# Our operations on the frame come here
|
||||
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
# Display the resulting frame
|
||||
cv2.imshow('frame',gray)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
|
||||
# When everything done, release the capture
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
32
example/ex4 - deepCopy.py
Normal file
32
example/ex4 - deepCopy.py
Normal file
@ -0,0 +1,32 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import copy
|
||||
|
||||
image = cv2.imread('./res/balls.png')
|
||||
if image is None:
|
||||
print("\nERROR: Could not open image\n")
|
||||
exit()
|
||||
|
||||
# Bepaal afmetingen en aantal kleurkanalen
|
||||
height = image.shape[0]
|
||||
width = image.shape[1]
|
||||
colors = image.shape[2]
|
||||
print ("%d pixels breed" % width)
|
||||
print ("%d pixels hoog" % height)
|
||||
print ("%d kleur kanalen" % colors)
|
||||
|
||||
#snij een selectie uit het plaatje
|
||||
# dit maakt een copy van het adres van het plaatje:
|
||||
selection1 = image[10:150, 10:200] ## Dit is een reference, python doet dit om geheugen te besparen
|
||||
# dit maakt een echte copy van een deel van het plaatje:
|
||||
selection2 = copy.deepcopy(image[10:150, 10:200]) ## Dit is een daadwerkelijke kopie op een nieuwe locatie
|
||||
# de kleuren kun je zetten door een zogenaamd tupplet van kleur (50,250,50)
|
||||
image[10:150, 10:200] = (50,250,50) ## Hier zet je de waarde van de afbeelding op groen dus ook die van de reference
|
||||
|
||||
# Toon het beeld in een venster
|
||||
cv2.imshow("Cut-out1", selection1)
|
||||
cv2.imshow("Cut-out2", selection2)
|
||||
cv2.imshow("Input image", image)
|
||||
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
44
example/ex5 - blue.py
Normal file
44
example/ex5 - blue.py
Normal file
@ -0,0 +1,44 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
cap = cv2.VideoCapture(0)
|
||||
|
||||
while(1):
|
||||
# Take each frame
|
||||
ret, frame = cap.read()
|
||||
|
||||
# Convert BGR to HSV
|
||||
hsv = cv2.cvtColor(frame, cv2.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 = cv2.inRange(hsv, lower_blue, upper_blue)
|
||||
|
||||
blue_amnt = mask.mean()
|
||||
blue_str = ""
|
||||
if blue_amnt < 10:
|
||||
blue_str = "not very blue"
|
||||
elif blue_amnt >= 10 and blue_amnt < 30:
|
||||
blue_str = "a bit blue"
|
||||
elif blue_amnt >= 30 and blue_amnt < 100:
|
||||
blue_str = "very blue"
|
||||
elif blue_amnt >= 100:
|
||||
blue_str = "all blue"
|
||||
|
||||
# Bitwise-AND mask and original image
|
||||
res = cv2.bitwise_and(frame,frame, mask= mask)
|
||||
|
||||
cv2.putText(res, blue_str, (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
||||
|
||||
cv2.imshow('frame',frame)
|
||||
cv2.imshow('mask',mask)
|
||||
cv2.imshow('res',res)
|
||||
|
||||
k = cv2.waitKey(5) & 0xFF
|
||||
if k == 27:
|
||||
break
|
||||
|
||||
cv2.destroyAllWindows()
|
16
example/ex6 - histogram.py
Normal file
16
example/ex6 - histogram.py
Normal file
@ -0,0 +1,16 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import os
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
# Load an color image in grayscale
|
||||
img = cv2.imread(os.path.join(os.getcwd(), "./res/bwg.png"), 0)
|
||||
|
||||
hist = cv2.calcHist([img], [0], None, [256], [0,256])
|
||||
|
||||
# show the plotting graph of an image
|
||||
plt.plot(hist)
|
||||
plt.show()
|
||||
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
23
example/ex7 - histogram eq.py
Normal file
23
example/ex7 - histogram eq.py
Normal file
@ -0,0 +1,23 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import os
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
# Load an color image in grayscale
|
||||
img = cv2.imread(os.path.join(os.getcwd(), "./res/bwg.png"), 0)
|
||||
imgEq = cv2.equalizeHist(img)
|
||||
|
||||
cv2.imshow('in',img)
|
||||
cv2.imshow('out',imgEq)
|
||||
|
||||
hist = cv2.calcHist([img], [0], None, [256], [0,256])
|
||||
histEq = cv2.calcHist([imgEq], [0], None, [256], [0,256])
|
||||
|
||||
|
||||
# show the plotting graph of an image
|
||||
plt.plot(hist)
|
||||
plt.plot(histEq)
|
||||
plt.show()
|
||||
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
BIN
res/balls.png
Normal file
BIN
res/balls.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 62 KiB |
BIN
res/bw.png
Normal file
BIN
res/bw.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 388 B |
BIN
res/bwg.png
Normal file
BIN
res/bwg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 256 B |
BIN
res/drake.png
Normal file
BIN
res/drake.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
BIN
res/grad.png
Normal file
BIN
res/grad.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
BIN
res/ohno.png
Normal file
BIN
res/ohno.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 105 KiB |
0
src/nuts.py
Normal file
0
src/nuts.py
Normal file
Loading…
Reference in New Issue
Block a user