반응형
이 자료는 한국인공지능협회에서 진행한 2021년 사업주 직업능력 개발훈련으로 BASIC AI(32시간)-박성주 강사의 온라인 교육내용을 참고한 것입니다.
In [ ]:
# jupyter에서 외부에 있는 명령을 수행하기 위해서는 !를 사용한다.
주요 모듈 설치¶
In [2]:
!pip install opencv-python
Collecting opencv-python
Downloading opencv_python-4.5.4.60-cp36-cp36m-win_amd64.whl (35.1 MB)
Requirement already satisfied: numpy>=1.13.3 in c:\programdata\anaconda3\envs\p36t19_beauty\lib\site-packages (from opencv-python) (1.19.5)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.5.4.60
주요 및 추가 모듈 설치¶
In [3]:
!pip install opencv-contrib-python
Collecting opencv-contrib-python
Downloading opencv_contrib_python-4.5.4.60-cp36-cp36m-win_amd64.whl (42.0 MB)
Requirement already satisfied: numpy>=1.13.3 in c:\programdata\anaconda3\envs\p36t19_beauty\lib\site-packages (from opencv-contrib-python) (1.19.5)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-4.5.4.60
In [6]:
import cv2
In [7]:
cv2.__version__
Out[7]:
'4.5.4'
In [10]:
import numpy as np
In [ ]:
imgfile = 'imgs/test2.jpg'
img = cv2.imread(imgfile, cv2.IMREAD_COLOR)
cv2.imshow('수지', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
In [ ]:
#haarcascade_frontalface_default.xml 다운로드
라이브러리 불러오기¶
In [ ]:
import numpy as np
import cv2
In [5]:
detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
프로그램을 실행하여 얼굴인식하기¶
In [ ]:
while (True):
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.imshow('frame', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
# Face_68point_Detection
In [1]:
import sys
import os
import dlib
import glob
In [5]:
predictor_path = "models/shape_predictor_68_face_landmarks.dat"
faces_folder_path = "imgs/test2.jpg"
In [7]:
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
win = dlib.image_window()
In [8]:
f = faces_folder_path
print("Processing file: {}".format(f))
img = dlib.load_rgb_image(f)
win.clear_overlay()
win.set_image(img)
dets = detector(img, 1)
print("Number of faces detected: {}".format(len(dets)))
for k, d in enumerate(dets):
print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
k, d.left(), d.top(), d.right(), d.bottom()))
shape = predictor(img, d)
print("Part 0: {}, Part 1: {} ...".format(shape.part(0),
shape.part(1)))
win.add_overlay(shape)
win.add_overlay(dets)
dlib.hit_enter_to_continue()
Processing file: imgs/test2.jpg
Number of faces detected: 1
Detection 0: Left: 167 Top: 266 Right: 390 Bottom: 489
Part 0: (172, 316), Part 1: (176, 346) ...
In [ ]:
반응형
'그냥, 코딩' 카테고리의 다른 글
[개발자를 위한 머신러닝&딥러닝] 텐서플로(Tensorflow) 사용하기 (0) | 2022.10.04 |
---|---|
[개발자를 위한 머신러닝&딥러닝] 텐서플로(Tensorflow) 소개 (0) | 2022.10.04 |
GAN실습 - 환경구축 & BeautyGAN(2) (0) | 2021.12.16 |
GAN실습 - 환경구축 & BeautyGAN(1) (0) | 2021.12.16 |
GAN 알고리즘 소개 및 활용범위 (0) | 2021.12.16 |