#opencv #image-recognition #dlib
Вопрос:
Я создал папку с именем Изображения, которая содержит вложенные папки. В каждой подпапке хранятся изображения конкретного человека. Я хочу получить пути к каждому файлу в папке с именем Изображения. Я попытался распечатать список imagePaths, но он выдает пустой вывод.Пожалуйста, сообщите, в чем проблема? Помогите мне!
from imutils import paths
import face_recognition
import pickle
import cv2
import os
# get paths of each file in folder named Images
# Images here contains my data(folders of various persons)
imagePaths = list(paths.list_images('Images'))
knownEncodings = []
knownNames = []
print(imagePaths)
# loop over the image paths
for (i, imagePath) in enumerate(imagePaths):
# extract the person name from the image path
name = imagePath.split(os.path.sep)[-2]
# load the input image and convert it from BGR (OpenCV ordering)
# to dlib ordering (RGB)
image = cv2.imread(imagePath)
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Use Face_recognition to locate faces
boxes = face_recognition.face_locations(rgb ,model='hog')
# compute the facial embedding for the face
encodings = face_recognition.face_encodings(rgb, boxes)
# loop over the encodings
for encoding in encodings:
knownEncodings.append(encoding)
knownNames.append(name)
# save emcodings along with their names in dictionary data
data = {"encodings": knownEncodings, "names": knownNames}
# use pickle to save data into a file for later use
f = open("face_enc", "wb")
f.write(pickle.dumps(data))
f.close()
Комментарии:
1. пожалуйста, сократите свой код до «минимального воспроизводимого примера».