if cropped_face.shape[0] <= 0 or cropped_face.shape[1] <= 0:
                continue
            #test_face = cv2.resize(cropped_face,(out_size,out_size))
            cropped_face = cv2.cvtColor(cropped_face, cv2.COLOR_BGR2RGB)
            cropped_face = Image.fromarray(cropped_face)
            test_face = resize(cropped_face)
            test_face = to_tensor(test_face)
            test_face = normalize(test_face)
            test_face.unsqueeze_(0)

            start = time.time()
            ort_inputs = {
                ort_session.get_inputs()[0].name: to_numpy(test_face)
            }
            ort_outs = ort_session.run(None, ort_inputs)
            end = time.time()
            print('Time: {:.6f}s.'.format(end - start))
            landmark = ort_outs[0]
            #print(landmark)

            landmark = landmark.reshape(-1, 2)
            landmark = new_bbox.reprojectLandmark(landmark)
            img = drawLandmark_multiple(img, new_bbox, landmark)
        cv2.imshow('Face Alignment Demo', img)
        cv2.waitKey(30)
        if cv2.waitKey(10) == 27:  # Esc key to stop
            break
    cap.release()
    cv2.destroyAllWindows()
Exemplo n.º 2
0
                    2)

        cv2.putText(orig_image,
                    "EAR (L,R): ({:.2f},{:.2f})".format(earL,
                                                        earR), (x1, y2 + 20),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.55, (0, 255, 255), 2)

        #Detectando e sinalizando a piscada
        setP = 0.26  #Quanto menor mais fechado o olho precisa estar
        #if earL < setP and earR < setP: #forma mais dura, exige os dois olhos fechados
        if earMed < setP:  #sinaliza pela média dos dois olhos
            #Desenha bolinha da piscada e envia msg OSC
            cv2.circle(orig_image, (cx, y1 + 30), 30, (0, 255, 0), -1)
            client.send_message("/piscou", (earL, earR))

        #função que percorre o array landmarks e carimba todos os pontos
        orig_image = drawLandmark_multiple(orig_image, new_bbox, landmark)

    sum += boxes.shape[0]

    #Redução para exibição, caso necessário
    orig_image = cv2.resize(orig_image, (0, 0), fx=0.7, fy=0.7)

    cv2.imshow('Detector Neural de Piscadas (Tecle [q] para sair)', orig_image)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()
print("sum:{}".format(sum))