Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os, time
- import cognitive_face as CF
- from global_variables import personGroupId
- import urllib
- import sqlite3
- Key = '----some key----'
- CF.Key.set(Key)
- def get_person_id():
- person_id = ''
- extractId = str(sys.argv[1])[-2:]
- connect = sqlite3.connect("Face-DataBase")
- c = connect.cursor()
- cmd = "SELECT * FROM Students WHERE ID = " + extractId
- c.execute(cmd)
- row = c.fetchone()
- person_id = row[3]
- connect.close()
- return person_id
- if len(sys.argv) is not 1:
- currentDir = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
- imageFolder = os.path.join(currentDir, "dataset/" + str(sys.argv[1]))
- person_id = get_person_id()
- for filename in os.listdir(imageFolder):
- if filename.endswith(".jpg"):
- print(filename)
- try:
- with open('1.jpg', 'rb') as image:
- img = image.read()
- face_to_detect = bytearray(img)
- print("image reading done!")
- except Exception as ex:
- print("exception in reading image bytes {0}".format(ex.args))
- has_exception = True
- res = CF.face.detect(face_to_detect)
- if len(res) != 1:
- print ("No face detected in image")
- else:
- res = CF.person.add_face(face_to_detect, personGroupId, person_id)
- print(res)
- time.sleep(6)
- User.22.1.jpg
- image reading done!
- Traceback (most recent call last):
- File "add_person_faces1.py", line 38, in <module>
- res = CF.face.detect(face_to_detect)
- File "C:UsersAvinaAnaconda3envsvirtual_platformlibsite-packagescognitive_faceface.py", line 33, in detect
- headers, data, json = util.parse_image(image)
- File "C:UsersAvinaAnaconda3envsvirtual_platformlibsite-packagescognitive_faceutil.py", line 130, in parse_image
- elif os.path.isfile(image): # When image is a file path.
- File "C:UsersAvinaAnaconda3envsvirtual_platformlibgenericpath.py", line 30, in isfile
- st = os.stat(path)
- ValueError: stat: path too long for Windows
Add Comment
Please, Sign In to add comment