Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:“DetectedFace”对象不是可订阅的对象_Python_Azure_Face Recognition_Face Api_Vision Api - Fatal编程技术网

Python TypeError:“DetectedFace”对象不是可订阅的对象

Python TypeError:“DetectedFace”对象不是可订阅的对象,python,azure,face-recognition,face-api,vision-api,Python,Azure,Face Recognition,Face Api,Vision Api,错误: 下面的代码是代码块 from msrest.authentication import CognitiveServicesCredentials from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person, SnapshotObjectType, OperationStatusType import global_variables as global_var import os, u

错误:

下面的代码是代码块

from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person, SnapshotObjectType, OperationStatusType
import global_variables as global_var
import os, urllib
import sqlite3
from openpyxl import Workbook, load_workbook
from openpyxl.utils import get_column_letter, column_index_from_string
from openpyxl.cell import Cell
import time
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)



#get current date
currentDate = time.strftime("%d_%m_%y")
wb = load_workbook(filename = "reports.xlsx")
sheet = wb['Cse15']

def getDateColumn():
    for i in range(1, len(list(sheet.rows)[0]) + 1):
        col = get_column_letter(i)
        if sheet['%s%s'% (col,'1')].value == currentDate:
            return col

Key = global_var.key


ENDPOINT = 'https://centralindia.api.cognitive.microsoft.com'
face_client = FaceClient(ENDPOINT,CognitiveServicesCredentials(Key))


connect = sqlite3.connect("Face-DataBase")


attend = [0 for i in range(60)] 

currentDir = os.path.dirname(os.path.abspath(__file__))
directory = os.path.join(currentDir, 'Cropped_faces')
for filename in os.listdir(directory):
    if filename.endswith(".jpg"):
        print(filename)
        img_data = open(os.path.join(directory,filename), "rb")
        res = face_client.face.detect_with_stream(img_data)
        print("Res = {}".format(res))

        if len(res) < 1:
            print("No face detected.")
            continue

        faceIds = []
        for face in res:
            faceIds.append(face['faceId'])      #error occuring line
        res = face_client.face.identify(faceIds, global_var.personGroupId)
        print(filename)
        print("res = {}".format(res))

        for face  in res:
            if not face['candidates']:
                print("Unknown")
            else:
                personId = face['candidates'][0]['personId']
                print("personid = {}".format(personId))
                #cmd =  + personId
                cur = connect.execute("SELECT * FROM Students WHERE personID = (?)", (personId,))
                #print("cur = {}".format(cur))
                for row in cur:
                    print("aya")
                    print("row = {}".format(row))
                    attend[int(row[0])] += 1
                print("---------- " + row[1] + " recognized ----------")
        time.sleep(6)

for row in range(2, len(list(sheet.columns)[0]) + 1):
    rn = sheet.cell(row = row, column  =1).value
    if rn is not None:
        print("rn = {}".format(rn))
        rn = rn[-2:]
        if attend[int(rn)] != 0:
            col = getDateColumn()
            print("col = {}".format(col))
            sheet['%s%s' % (col, str(row))] = 0

wb.save(filename = "reports.xlsx")      
这是一个自动考勤系统,可捕获多张人脸并在excel工作表中进行更新。Azure认知人脸API用于人脸检测。 我希望新API的对象已经改变。此代码包含azure旧版本的推荐,但现在已更改。如果有人知道如何解决此错误,请提供帮助

from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person, SnapshotObjectType, OperationStatusType
import global_variables as global_var
import os, urllib
import sqlite3
from openpyxl import Workbook, load_workbook
from openpyxl.utils import get_column_letter, column_index_from_string
from openpyxl.cell import Cell
import time
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)



#get current date
currentDate = time.strftime("%d_%m_%y")
wb = load_workbook(filename = "reports.xlsx")
sheet = wb['Cse15']

def getDateColumn():
    for i in range(1, len(list(sheet.rows)[0]) + 1):
        col = get_column_letter(i)
        if sheet['%s%s'% (col,'1')].value == currentDate:
            return col

Key = global_var.key


ENDPOINT = 'https://centralindia.api.cognitive.microsoft.com'
face_client = FaceClient(ENDPOINT,CognitiveServicesCredentials(Key))


connect = sqlite3.connect("Face-DataBase")


attend = [0 for i in range(60)] 

currentDir = os.path.dirname(os.path.abspath(__file__))
directory = os.path.join(currentDir, 'Cropped_faces')
for filename in os.listdir(directory):
    if filename.endswith(".jpg"):
        print(filename)
        img_data = open(os.path.join(directory,filename), "rb")
        res = face_client.face.detect_with_stream(img_data)
        print("Res = {}".format(res))

        if len(res) < 1:
            print("No face detected.")
            continue

        faceIds = []
        for face in res:
            faceIds.append(face['faceId'])      #error occuring line
        res = face_client.face.identify(faceIds, global_var.personGroupId)
        print(filename)
        print("res = {}".format(res))

        for face  in res:
            if not face['candidates']:
                print("Unknown")
            else:
                personId = face['candidates'][0]['personId']
                print("personid = {}".format(personId))
                #cmd =  + personId
                cur = connect.execute("SELECT * FROM Students WHERE personID = (?)", (personId,))
                #print("cur = {}".format(cur))
                for row in cur:
                    print("aya")
                    print("row = {}".format(row))
                    attend[int(row[0])] += 1
                print("---------- " + row[1] + " recognized ----------")
        time.sleep(6)

for row in range(2, len(list(sheet.columns)[0]) + 1):
    rn = sheet.cell(row = row, column  =1).value
    if rn is not None:
        print("rn = {}".format(rn))
        rn = rn[-2:]
        if attend[int(rn)] != 0:
            col = getDateColumn()
            print("col = {}".format(col))
            sheet['%s%s' % (col, str(row))] = 0

wb.save(filename = "reports.xlsx")