Guest User

Untitled

a guest
Jan 23rd, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import sys
  2. import os, time
  3. import cognitive_face as CF
  4. from global_variables import personGroupId
  5. import urllib
  6. import sqlite3
  7.  
  8. Key = '----some key----'
  9. CF.Key.set(Key)
  10.  
  11. def get_person_id():
  12. person_id = ''
  13. extractId = str(sys.argv[1])[-2:]
  14. connect = sqlite3.connect("Face-DataBase")
  15. c = connect.cursor()
  16. cmd = "SELECT * FROM Students WHERE ID = " + extractId
  17. c.execute(cmd)
  18. row = c.fetchone()
  19. person_id = row[3]
  20. connect.close()
  21. return person_id
  22.  
  23. if len(sys.argv) is not 1:
  24. currentDir = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
  25. imageFolder = os.path.join(currentDir, "dataset/" + str(sys.argv[1]))
  26. person_id = get_person_id()
  27. for filename in os.listdir(imageFolder):
  28. if filename.endswith(".jpg"):
  29. print(filename)
  30. try:
  31. with open('1.jpg', 'rb') as image:
  32. img = image.read()
  33. face_to_detect = bytearray(img)
  34. print("image reading done!")
  35. except Exception as ex:
  36. print("exception in reading image bytes {0}".format(ex.args))
  37. has_exception = True
  38. res = CF.face.detect(face_to_detect)
  39. if len(res) != 1:
  40. print ("No face detected in image")
  41. else:
  42. res = CF.person.add_face(face_to_detect, personGroupId, person_id)
  43. print(res)
  44. time.sleep(6)
  45.  
  46. User.22.1.jpg
  47. image reading done!
  48. Traceback (most recent call last):
  49. File "add_person_faces1.py", line 38, in <module>
  50. res = CF.face.detect(face_to_detect)
  51. File "C:UsersAvinaAnaconda3envsvirtual_platformlibsite-packagescognitive_faceface.py", line 33, in detect
  52. headers, data, json = util.parse_image(image)
  53. File "C:UsersAvinaAnaconda3envsvirtual_platformlibsite-packagescognitive_faceutil.py", line 130, in parse_image
  54. elif os.path.isfile(image): # When image is a file path.
  55. File "C:UsersAvinaAnaconda3envsvirtual_platformlibgenericpath.py", line 30, in isfile
  56. st = os.stat(path)
  57. ValueError: stat: path too long for Windows
Add Comment
Please, Sign In to add comment