def kairos(crop, cuantos): cv2.imwrite("faces/{}.jpg".format(unique_filename), crop) cv2.imwrite("faces/face.jpg".format(unique_filename), crop) recognized_faces = kairos_face.detect_face(file="faces/face.jpg") if recognized_faces != "Error": edad = recognized_faces['images'][0]['faces'][0]['attributes']['age'] sexo = recognized_faces['images'][0]['faces'][0]['attributes'][ 'gender']['type'] if sexo == 'M': sexo = "HOMBRE" else: sexo = "MUJER" print("edad: {}, sexo: {}".format(edad, sexo)) now = datetime.datetime.now() img = cv2.imread('p3.png', 1) font = cv2.FONT_HERSHEY_DUPLEX hora = str(now.hour) + ":" + str(now.minute) age = str(edad) cv2.putText(img, hora, (950, 510), font, 1.7, (0, 0, 255), 2) cv2.putText(img, sexo, (680, 583), font, 1.7, (0, 0, 255), 2) cv2.putText(img, age, (870, 663), font, 1.7, (0, 0, 255), 2) s_img = cv2.imread("faces/face.jpg") s_img2 = cv2.resize(s_img, (int(443), int(590))) cv2.imwrite("faces/face2.jpg", s_img2) s_img3 = cv2.imread("faces/face2.jpg") cv2.imwrite("faces/face2.jpg", s_img2) x_offset = 0 y_offset = 210 img[y_offset:y_offset + 590, x_offset:x_offset + 443] = s_img3 cv2.imwrite("faces/anuncio.jpg", img) from subprocess import call
def detect_face_fn(img_path): # detected_face = kf.detect_face(file=img_path, gallery_name='members') detected_face = kf.detect_face(file=img_path) # print(detected_face) print(detected_face['images'][0]['status'])
# kairos current_index = -1 with open('eyes.csv', 'w') as csvfile: spamwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) for index in o.ret: if (current_index == index[0]): continue has_face = True try: print("Send frame %d to Kairos" % index[0]) recognized_faces = kairos_face.detect_face(file="frame" + str(index[0]) + ".jpg") except kairos_face.exceptions.ServiceRequestError: has_face = False if (has_face): print("Calculate on frame %d" % index[0]) r_Y = recognized_faces.get(u'images')[0].get(u'faces')[0].get( u'rightEyeCenterY') r_X = recognized_faces.get(u'images')[0].get(u'faces')[0].get( u'rightEyeCenterX') l_Y = recognized_faces.get(u'images')[0].get(u'faces')[0].get( u'leftEyeCenterY') l_X = recognized_faces.get(u'images')[0].get(u'faces')[0].get( u'leftEyeCenterX') dist = dist_two_points(r_X, l_X, r_Y, l_Y) ratio = float(sys.argv[3]) / dist
def detect_faces(url): try: faces = kairos_face.detect_face(url=url) except Exception, e: print str(e) return None
import kairos_face as kf kf.settings.app_id = 'ypur app id' kf.settings.app_key = 'your app key' # galleries_list=kf.get_galleries_names_list() # # print(galleries_list) # # gallery_sub=kf.get_gallery('a-gallery') # # print(gallery_sub) recognized_faces = kf.detect_face(file='harry-meghan-15.jpg') detected_faces = kf.recognize_face(file='harry-meghan-15.jpg', gallery_name='a-gallery')
def recognize(request): try: cur = connection.cursor() logging.info('DB connected') except: logging.info('Db connection error') kairos_face.settings.app_id = 'Your App ID' kairos_face.settings.app_key = 'Your App key' if request.method == 'POST': #POST goes here . is_ajax is must to capture ajax requests. if request.is_ajax(): gallery = request.POST.get('gallery') image = request.POST.get('image') try: recognized_faces = kairos_face.recognize_face( file=image, gallery_name=gallery) uname = recognized_faces['images'][0]['candidates'][0][ 'subject_id'] result = 'success' except: result = 'error' uname = '' if result == 'success': cur.execute(''' select * from cv where uname=%s''', (uname, )) res = cur.fetchall() newlist = [ele for ele in res[0]] email = str(newlist[1]) designation = str(newlist[3]) team = str(newlist[4]) qresult = 'success' else: qresult = 'error' email = '' designation = '' team = '' detected_faces = kairos_face.detect_face(file=image) gen = detected_faces['images'][0]['faces'][0]['attributes'][ 'gender']['type'] age = detected_faces['images'][0]['faces'][0]['attributes']['age'] gender = '' if gen == 'M': gender = 'Male' else: gender = 'Female' data = { 'uname': uname, 'email': email, 'designation': designation, 'team': team, 'result': result, 'qresult': qresult, 'gender': gender, 'age': age } return JsonResponse(data) return render(request, 'recognize.html')
elif op == "2": '''url = "https://api.kairos.com/detect" headers = { "app_id": "2b0335d7", "app_key": "28e7a2915e876413a7f33b2eccd06a62" } # Detect from a file files= {'image':open(location,'rb')} r = requests.post(url, files=files, headers=headers) print(r.text)''' # Detect from a file detected_faces = kairos_face.detect_face(file=location) print(detected_faces) # for recognizing image elif op == "3": # Recognizing from a file recognized_faces = kairos_face.recognize_face(file=location, gallery_name='Demo') print(recognized_faces) #load and read string type data from json file #data = json.loads(recognized_faces) # read dictionary type data into str type data # now data is in the form of string so can apply .loads() method to it data = json.dumps(recognized_faces)
def detect(image_name): # Detect from a file recognized_faces = kairos_face.detect_face(file=image_name, gallery_name='student') print(recognized_faces)
fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter(DEST_FILE, fourcc, 20.0, (height, width)) cnt = 0 while (cap.isOpened()): ret, frame = cap.read() if ret == True: cv2.imwrite("frame_tmp.jpg", frame) has_face = True try: print("Send frame %d to Kairos" % cnt) recognized_faces = kairos_face.detect_face(file="frame_tmp.jpg") except kairos_face.exceptions.ServiceRequestError: has_face = False if (has_face): print("Calculate on frame %d" % cnt) r_Y = recognized_faces.get(u'images')[0].get(u'faces')[0].get( u'rightEyeCenterY') r_X = recognized_faces.get(u'images')[0].get(u'faces')[0].get( u'rightEyeCenterX') l_Y = recognized_faces.get(u'images')[0].get(u'faces')[0].get( u'leftEyeCenterY') l_X = recognized_faces.get(u'images')[0].get(u'faces')[0].get( u'leftEyeCenterX')
def detect(facePhoto=None): try: dict_responJSON = kairos_face.detect_face(file=facePhoto) except Exception, err: dict_responJSON = None
import kairos_face as kf # setting up keys kf.settings.app_id = "a123a233" kf.settings.app_key = "03a5065270150ba0e23a0584ae716b0d" file_path = input("Image URL") #enrolling new face kf.enroll_face(file=file_path, subject_id='s1', gallery_name="test") #detect face print(kf.detect_face(file=file_path, gallery_name="test"))
fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter(DEST_FILE, fourcc, 20.0, (height, width)) cnt = 0 while(cap.isOpened()): ret, frame = cap.read() if ret == True: cv2.imwrite("frame_tmp.jpg", frame) has_face = True try: print ("Send frame %d to Kairos" % cnt) recognized_faces = kairos_face.detect_face(file="frame_tmp.jpg") except kairos_face.exceptions.ServiceRequestError: has_face = False if (has_face): print ("Calculate on frame %d" % cnt) r_Y = recognized_faces.get(u'images')[0].get(u'faces')[0].get(u'rightEyeCenterY') r_X = recognized_faces.get(u'images')[0].get(u'faces')[0].get(u'rightEyeCenterX') l_Y = recognized_faces.get(u'images')[0].get(u'faces')[0].get(u'leftEyeCenterY') l_X = recognized_faces.get(u'images')[0].get(u'faces')[0].get(u'leftEyeCenterX') cv2.circle(frame, (r_X, r_Y), 3, (0, 0, 255), -1) cv2.circle(frame, (l_X, l_Y), 3, (0, 0, 255), -1) # write the flipped frame