如何给出正确的文件和文件夹地址



我已经试了一整天了,我不知道为什么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:UsersDELLDesktopNew folderfaces'
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:opencvface_reconization.py", line 14
paths=os.path.join(path=DIR,people)
^
SyntaxError: positional argument follows keyword argument
'''

我认为这个path=没有必要
更改

paths=os.path.join(path=DIR,people)

paths=os.path.join(DIR,people)

最新更新