【发布时间】:2021-05-29 07:59:11
【问题描述】:
我整天都在尝试这段代码,但我不知道为什么 DIR 在打开的 CV 模块中显示错误。 我需要解决这个问题 '''
import os
import cv2 as cv
import numpy as np
people=['emily','emma','jim parson']
haar_cas=cv.CascadeClassifier('haar_face.xml')
#
DIR=r'C:\Users\DELL\Desktop\New folder\faces'
features=[]
labels=[]
def train_face():
for person in people:
paths=os.path.join(path=DIR,people)
label=people.index(person)
for img in os.listdir(paths):
img_path=os.path.join(path,img)
img_array=cv.imread(img_path)
gray=cv.cvtColor(src=img_array,code=cv.COLOR_BGR2GRAY)
faces_rect=haar_cas.detectMultiScale(gray,scalefactor=1.1,minNeighbor=1)
for(x,y,w,h) in faces_rect:
faces_roi=gray[x:x+w , y:y+h]
features.append(faces_roi)
labels.append(label)
train_face()
print(f'length of the feature={len(features)}')
print(f'lenght of the labels={len(labels)}')
''' 这样的输出显示
'''
File "g:\opencv\face_reconization.py", line 14
paths=os.path.join(path=DIR,people)
^
SyntaxError: positional argument follows keyword argument
'''
【问题讨论】:
-
Python 有位置参数和关键字参数。位置参数需要在关键字参数之前提供。我建议查看 python 文档以获取更多详细信息。
标签: python python-3.x path