import face_recognition as fr
import os
import cv2
import face_recognition
import numpy as np
from PIL import ImageGrab
from time import sleep
def record():
img = ImageGrab.grab()
saveas = 'test.jpg'
img.save(saveas)
img = cv2.imread('test.jpg',1)
def get_encoded_faces():
"""
looks through the faces folder and encodes all
the faces
:return: dict of (name, image encoded)
"""
encoded = {}
for dirpath, dnames, fnames in os.walk("./faces"):
for f in fnames:
if f.endswith(".jpg") or f.endswith(".png"):
face = fr.load_image_file("faces/" + f)
encoding = fr.face_encodings(face)[0]
encoded[f.split(".")[0]] = encoding
return encoded
def unknown_image_encoded(img):
"""
encode a face given the file name
"""
face = fr.load_image_file("faces/" + img)
encoding = fr.face_encodings(face)[0]
return encoding
def classify_face(im):
"""
will find all of the faces in a given image and label
them if it knows what they are
:param im: str of file path
:return: list of face names
"""
faces = get_encoded_faces()
faces_encoded = list(faces.values())
known_face_names = list(faces.keys())
img = cv2.imread(im, 1)
# img = cv2.resize(img, (0, 0), fx=0.5, fy=0.5)
# img = img[:,:,::-1]
face_locations = face_recognition.face_locations(img)
unknown_face_encodings = face_recognition.face_encodings(img, face_locations)
face_names = []
for face_encoding in unknown_face_encodings:
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(faces_encoded, face_encoding)
name = "Unknown"
# use the known face with the smallest distance to the new face
face_distances = face_recognition.face_distance(faces_encoded, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]
face_names.append(name)
for (top, right, bottom, left), name in zip(face_locations, face_names):
# Draw a box around the face
cv2.rectangle(img, (left - 20, top - 20), (right + 20, bottom + 20), (255, 0, 0), 2)
# Draw a label with a name below the face
cv2.rectangle(img, (left - 20, bottom - 15), (right + 20, bottom + 20), (255, 0, 0), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(img, name, (left - 20, bottom + 15), font, 1.0, (255, 255, 255), 2)
# Display the resulting image
while True:
record()
cv2.imshow('Video', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
return face_names
print(classify_face("test.jpg"))
import os
import cv2
import face_recognition
import numpy as np
from PIL import ImageGrab
from time import sleep
def record():
img = ImageGrab.grab()
saveas = 'test.jpg'
img.save(saveas)
img = cv2.imread('test.jpg',1)
def get_encoded_faces():
"""
looks through the faces folder and encodes all
the faces
:return: dict of (name, image encoded)
"""
encoded = {}
for dirpath, dnames, fnames in os.walk("./faces"):
for f in fnames:
if f.endswith(".jpg") or f.endswith(".png"):
face = fr.load_image_file("faces/" + f)
encoding = fr.face_encodings(face)[0]
encoded[f.split(".")[0]] = encoding
return encoded
def unknown_image_encoded(img):
"""
encode a face given the file name
"""
face = fr.load_image_file("faces/" + img)
encoding = fr.face_encodings(face)[0]
return encoding
def classify_face(im):
"""
will find all of the faces in a given image and label
them if it knows what they are
:param im: str of file path
:return: list of face names
"""
faces = get_encoded_faces()
faces_encoded = list(faces.values())
known_face_names = list(faces.keys())
img = cv2.imread(im, 1)
# img = cv2.resize(img, (0, 0), fx=0.5, fy=0.5)
# img = img[:,:,::-1]
face_locations = face_recognition.face_locations(img)
unknown_face_encodings = face_recognition.face_encodings(img, face_locations)
face_names = []
for face_encoding in unknown_face_encodings:
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(faces_encoded, face_encoding)
name = "Unknown"
# use the known face with the smallest distance to the new face
face_distances = face_recognition.face_distance(faces_encoded, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]
face_names.append(name)
for (top, right, bottom, left), name in zip(face_locations, face_names):
# Draw a box around the face
cv2.rectangle(img, (left - 20, top - 20), (right + 20, bottom + 20), (255, 0, 0), 2)
# Draw a label with a name below the face
cv2.rectangle(img, (left - 20, bottom - 15), (right + 20, bottom + 20), (255, 0, 0), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(img, name, (left - 20, bottom + 15), font, 1.0, (255, 255, 255), 2)
# Display the resulting image
while True:
record()
cv2.imshow('Video', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
return face_names
print(classify_face("test.jpg"))
파이썬쓰고있어...
원본소스는 test.jpg 파일을 읽어서 faces폴더의 모델안에 해당얼굴이있으면
얼굴인식한 워터마크와함께 이미지를 보여주는건데
나는 화면상캡쳐를 실시간으로 무한반복하고 이것을 1로 저장시키고
이것을 다시 1을 인식해서
얼굴인식된 표시와 함께 2의 파일로 계속 덮어씌우고 이걸 보고싶은데
도움좀 주라.. 초보라서 내가 잘몰라 ㅠㅠ
알려주는사람 기프티콘줄게 제발 ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ
팀뷰어도 가능해 욕도 좋아..
씨발 오픈소스그대로가따박아놓고 이잉 안돼 이지랄하노 혼자연구좀해라이기야
지금 6시간째 하고있어 나 이것조차도 못해 ㅠㅠ 미안해.. 근데 하고싶어미칠거같아 정말
실시간 화면캡쳐 저장하는것도 존나오래걸렸어 이걸합치고싶어서..
기본문법모르면 난이도에맞는걸해 제발
그러지말고 알려주라 .. 뭐가잘못된거야 어떻게 해야하는거야??;;;;
시간낭비하지말라고 미리알려주면 저거 cv만든새끼한테 물어보는게 제일빠르다 이 코드 이해하려고 노력할새끼 여기없음
외국인이야.. 알았어 고마워
씨발 이걸 봐주려면 시간 꽤걸릴텐데 깊티로 퉁? 그리고 한번 손대주면 니가 컨펌해줄때까지 봐줘야할텐데 그건 더 싫고
이거 오래걸려?? 이미 짜여져있는소스에 내가 실시간으로 화면캡쳐 한거 계속 덮어씌우는것을 넣는건데 짤게있어??? 고수들도 어려운거야?
간단하건 복잡하건 어쨌든 구조를 이해하려면 이 코드를 다 읽어야되는데 다른사람들이 이걸 읽고 해결해줄거라 생각하냐?
아 그렇구나 알았어 미안해,,
해당 댓글은 삭제되었습니다.
오 진짜요 ?? 카톡 남겨드립니다 appointment
엥?? 바로 된다구요??