【问题标题】:how to give proper address of file and folder?如何给出文件和文件夹的正确地址?
【发布时间】: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


【解决方案1】:

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

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

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

【讨论】:

  • 它说 typeError: join() argument must be str or bytes, not 'list' 不起作用
  • 而不是 od 人,像 paths=os.path.join(DIR,person) 一样传递人
猜你喜欢
  • 2021-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-11
相关资源
最近更新 更多