лаба 1 рабочая
This commit is contained in:
parent
fffd3dbe72
commit
0f101d9dd8
BIN
lab1/image/apple.bmp
Normal file
BIN
lab1/image/apple.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 325 KiB |
16
lab1/image/main.py
Normal file
16
lab1/image/main.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import cv2
|
||||||
|
|
||||||
|
src = cv2.imread('apple.bmp', 1)
|
||||||
|
cv2.imshow('original', src)
|
||||||
|
imgray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
|
||||||
|
cv2.imshow('gray', imgray)
|
||||||
|
|
||||||
|
_, tresh = cv2.threshold(imgray, 127, 255, 0)
|
||||||
|
cv2.imshow('tresh', tresh)
|
||||||
|
|
||||||
|
contours, _ = cv2.findContours(tresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
||||||
|
|
||||||
|
cv2.drawContours(src, contours, -1, (0, 255, 0), 2)
|
||||||
|
cv2.imshow('eye', src)
|
||||||
|
cv2.waitKey(0)
|
||||||
|
cv2.destroyAllWindows()
|
12213
lab1/video/haarcascade_eye.xml
Normal file
12213
lab1/video/haarcascade_eye.xml
Normal file
File diff suppressed because it is too large
Load Diff
33314
lab1/video/haarcascade_frontalface_default.xml
Normal file
33314
lab1/video/haarcascade_frontalface_default.xml
Normal file
File diff suppressed because it is too large
Load Diff
43
lab1/video/main.py
Normal file
43
lab1/video/main.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import cv2
|
||||||
|
|
||||||
|
# Загружаем обученные модели
|
||||||
|
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
||||||
|
eyeCascade = cv2.CascadeClassifier('haarcascade_eye.xml')
|
||||||
|
|
||||||
|
cap = cv2.VideoCapture(0) # Открываем видеопоток с камеры
|
||||||
|
cap.set(cv2.CAP_PROP_FPS, 60) # Частота кадров
|
||||||
|
|
||||||
|
while True:
|
||||||
|
ret, video = cap.read() # Считываем видео
|
||||||
|
gray = cv2.cvtColor(video, cv2.COLOR_BGR2GRAY) # Красим все, так удобнее
|
||||||
|
|
||||||
|
faces = faceCascade.detectMultiScale(
|
||||||
|
gray,
|
||||||
|
scaleFactor=1.2,
|
||||||
|
minNeighbors=5,
|
||||||
|
minSize=(20, 20)
|
||||||
|
)
|
||||||
|
|
||||||
|
for (x, y, w, h) in faces:
|
||||||
|
roi_gray = gray[y:y + h, x:x + w] # Вырезаем область с лицами
|
||||||
|
roi_color = video[y:y + h, x:x + w]
|
||||||
|
|
||||||
|
cv2.rectangle(video, (x, y), (x + w, y + h), (255, 0, 0), 2) #
|
||||||
|
|
||||||
|
eyes = eyeCascade.detectMultiScale(
|
||||||
|
roi_gray,
|
||||||
|
scaleFactor = 1.2,
|
||||||
|
minNeighbors = 4,
|
||||||
|
minSize = (5, 5),
|
||||||
|
)
|
||||||
|
|
||||||
|
for (ex, ey, ew, eh) in eyes:
|
||||||
|
cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)
|
||||||
|
|
||||||
|
cv2.imshow("output", video) # Выводим видео в окно
|
||||||
|
|
||||||
|
if cv2.waitKey(10) == 27: # Выходим по кнопке Esc
|
||||||
|
break
|
||||||
|
|
||||||
|
cap.release()
|
||||||
|
cv2.destroyAllWindows()
|
Reference in New Issue
Block a user