python - Django 无法打开 shape_predictor_68_face_landmarks.dat。RuntimeError:无法打开 shape_predictor_68_face_landmarks.dat
问题描述
我的 Django 应用程序无法在视图中打开 shape_predictor_68_face_landmarks.dat。但在简单的 .py 文件中,此代码有效。请帮助解决这个问题。我曾尝试使用线程和 asycno,但它不起作用。
class Main(View):
def post(self, request):
images = Images.objects.all()
image = request.FILES.get('image')
name = request.POST.get('name')
if not image and not name:
# images = Images.objects.all()
return render(request, 'find_photo/main.html', context={'images': images, 'result': True, })
group = Groups.objects.create(photo=image, title=name,)
find_photos("../" + group.photo.url)
# x = threading.Thread(target=find_photos, args=("../" + group.photo.url,))
# x.setDaemon(True)
# x.start()
#
# print(x.is_alive())
# mypath = '/find_photos/'
# onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
#
# for file in onlyfiles:
# print(file)
# group.find_images.add(file)
# group.save()
return render(request, 'find_photo/main.html', context={'images': images, })
查找照片功能:
def find_photos(image):
sp = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
face_rec = dlib.face_recognition_model_v1('dlib_face_recognition_resnet_model_v1.dat')
detector = dlib.get_frontal_face_detector()
min_distance = 2
f1 = get_face_descriptors(image, sp, face_rec, detector)[0]
files = getfilelist(dirpath)
flag = 0
for f in files:
flag = flag + 1
print('Анализ ' + f + ' - ' + str(flag) + ' фото из ' + str(vsego))
if os.path.exists(f):
try:
findfaces = get_face_descriptors(f)
print('На фото: ' + str(len(findfaces)) + ' лиц')
for f2 in findfaces:
if (f2 != []):
euc_distance = distance.euclidean(f1, f2)
print(euc_distance)
if euc_distance < 0.65:
print('Найдено лицо: ' + f)
shutil.copyfile(f, resultpath + str(flag) + '.jpg')
except:
continue
print("DONE")
解决方案
推荐阅读
- reactjs - 是
与 Typescript 中的 <{}, {}> 相同吗? - r - 如何将书面序列转换为数字序列?(右)
- php - 如何正确存储注册用户和其他与会者所需的信息?(场景 1 有效,但场景 2 和 3 无效)
- reactjs - setState 不适用于更新 React 中的数组
- vagrant - 无法在 MacOSX 上安装 Vagrant + VirtualBox
- php - 查询复制结果
- git - 合并后丢失 git name 分支信息
- python - FLASK - 第 1 行 '%(site_id)s' 附近的 SQL 语法有错误
- python - 在 Pandas 中未正确附加行
- ruby-on-rails - 带有新父子的表单上的 Rails 模型验证