1

Please could someone help? I have scoured the web and obviously Stackoverflow and yet i am still getting bugs that look simple to solve but are actually not (for me anyway) i am pretty new with python working on code tutorials and not really learning much until I've started trying to create projects like this. Please excuse my comments!:)

%matplotlib inline
from matplotlib.pyplot import imshow
from PIL import Image
import requests
from io import BytesIO

import numpy as np 
import imageio
import matplotlib.pyplot as plt
from PIL import Image

im1 = imageio.imread('DM.jpg') #Read the image from the desktop
# print(im1.shape) #Returns the number of rows, columns and channels (if image is colour returns "3")

#plt.imshow(im1)
#plt.show() !!!This works.Take away the hash tag and it will show the image!!!

#New script to try a face recognition
faceURI = "https://*****************azure.com/"
faceKey = "*********************"

import cognitive_face as CF

# Set URI and Key
CF.BaseUrl.set(faceURI)
CF.Key.set(faceKey)

# Detect faces in an image
img_url = 'DM.jpg'
result = CF.face.detect(img_url)
print (result)

So i now believe where i am going wrong? The part where it has in code about the end point and the key should not be there but be in a bash file. Now that's where i'm having trouble now! haha (it doesnt rain but pours!). i am trying to use vim however this is something new and now i'm struggling with that *facepalms myself

Towvis
  • 21
  • 7

1 Answers1

1

Although I am not quite sure about the exact ask on the piece of code you shared, but I would suggest you to go through the official examples below for end to end guide and then try to run/debug those code examples on your local machine. (One way to learn something new is to play with lot of examples of others' code :))

Quickstart: Use the Face client library

Quickstart: Detect faces in an image using the Face REST API and Python

Update: Coming back to your code and follow up clarification on the ask. I see a problem where you are trying use the cognitive face SDK. I don't see you creating the FaceClient object in your code! Something like: face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(KEY))

krishg
  • 5,935
  • 2
  • 12
  • 19
  • Thank you, I have been through these before but i agree with what you are saying and getting the best learning experience is to keep debugging. Sorry my main ask about this code is that i can never get it to work! I feel like the cognitive service is not recognising the image? it works and shows the image before i start using the cf function then it stops? – Towvis Aug 28 '20 at 23:34
  • where are you creating the FaceClient object in you code? Something llike: `face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(KEY))` – krishg Aug 29 '20 at 10:56
  • Hi Krishnendu, I havent created a Faceclient object so hopefully that is the missing link? i will try that and fingers crossed it will work! – Towvis Aug 30 '20 at 20:51
  • probably yes :) – krishg Aug 30 '20 at 22:45