2024-11-07
Discord –> @nfpl242_automatizace –> pište DM
$vsm_measure PROJECT TOKEN [branch]
default branch je master
, PROJECT je číslo projektu
import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(6,7));
# BGR to HSV
hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
plt.subplot(2,2,1); plt.imshow(hsv)
plt.axis('off')
# BGR to L*a*b
lab = cv.cvtColor(img, cv.COLOR_BGR2LAB)
plt.subplot(2,2,2); plt.imshow(lab)
plt.axis('off')
# BGR to RGB
rgb = cv.cvtColor(img, cv.COLOR_BGR2RGB)
plt.subplot(2,2,3); plt.imshow(rgb)
plt.axis('off')
# BGR
plt.subplot(2,2,4); plt.imshow(img)
plt.axis('off')
plt.show()
blank = np.zeros(img.shape[:2], dtype='uint8')
b,g,r = cv.split(img)
plt.figure(figsize=(6,7));
blue = cv.merge([b,blank,blank])
green = cv.merge([blank,g,blank])
red = cv.merge([blank,blank,r])
plt.subplot(1,3,1);plt.imshow(blue);plt.axis('off')
plt.subplot(1,3,2);plt.imshow(green);plt.axis('off')
plt.subplot(1,3,3);plt.imshow(red);plt.axis('off')
plt.show()
h,s,v = cv.split(hsv)
plt.figure(figsize=(8,7));
plt.subplot(1,4,1); plt.imshow(h, cmap='gray')
plt.title('hue')
plt.axis('off')
plt.subplot(1,4,2); plt.imshow(s, cmap='gray')
plt.title('saturation')
plt.axis('off')
plt.subplot(1,4,3); plt.imshow(v, cmap='gray')
plt.title('value')
plt.axis('off')
plt.subplot(1,4,4); plt.imshow(rgb)
plt.title('original')
plt.axis('off')
plt.show()
h,s,v = cv.split(lab)
plt.figure(figsize=(8,7));
plt.subplot(1,4,1); plt.imshow(h, cmap='gray')
plt.title('lightness')
plt.axis('off')
plt.subplot(1,4,2); plt.imshow(s, cmap='gray')
plt.title('a')
plt.axis('off')
plt.subplot(1,4,3); plt.imshow(v, cmap='gray')
plt.title('b')
plt.axis('off')
plt.subplot(1,4,4); plt.imshow(rgb)
plt.title('original')
plt.axis('off')
plt.show()
Viola, P. and Jones, M. Rapid object detection using a boosted cascade of simple features. Proceedings of CVPR 2001 (Vol. 1, 2001) doi:10.1109/CVPR.2001.990517
OpenCV obsahuje předučená data.
people = cv.imread('people.jpg')
people = cv.cvtColor(people, cv.COLOR_BGR2RGB)
gray = cv.cvtColor(people, cv.COLOR_BGR2GRAY)
#gray = cv.equalizeHist(gray)
haar_cascade = cv.CascadeClassifier('haar_face.xml')
faces_rect = haar_cascade.detectMultiScale(
gray, scaleFactor=1.06, minNeighbors=4)
for (x,y,w,h) in faces_rect:
cv.rectangle(people, (x,y), (x+w,y+h),
(0,255,0), thickness=2)
print(f'Nalezeno {len(faces_rect)} obličejů.')
plt.figure(figsize=(8,6));
plt.imshow(people)
plt.axis('off')
plt.show()
Nalezeno 29 obličejů.
opencv_createsamples
opencv_annotation
- naklikáte objekty z obrázkuopencv_traincascade
opencv_visualisation
Pozor: Tyto nástroje nejsou součástí OpenCV 4, nutno stáhnout starou verzi.
Úkol - kolik lidí je v KFKL na oddělení?
haar_cascade.detectMultiScale
hdgigante/python-opencv:4.10.0-alpine