def checkin_upload2():
    """Attention:

        Now stipulate that Only Two Photos will be uploaded
            And This api used for the first photo uploaded

    :return:

    """
    side_rate = 0

    result = "This is the Original Value of the result !"

    detector_forcheckin = detector

    sp_forcheckin = sp

    facerec_forcheckin = facerec

    dir_path = '/var/www/demoapp/Accounts'

    dirpath_forcheckin = "/var/www/demoapp/student_photo"

    upload_file = request.files['image01']

    if upload_file and allowed_file(upload_file.filename):
        filename = secure_filename(upload_file.filename)

        upload_file.save(
            os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename))

        name = request.form.get('name', 'little apple')

        class_name = request.form.get('class_name', 'little apple')

        result, side_rate = faceRecognzedProcess(
            detector_forcheckin, sp_forcheckin, facerec_forcheckin, dir_path,
            class_name, name, dirpath_forcheckin, upload_file.filename)

        os.remove(dirpath_forcheckin + '/' + upload_file.filename)

    if result == "Good !":
        mark_path = dir_path + '/' + class_name + '/' + name + '/' + "mark1.txt"
        if os.path.exists(mark_path) == True:
            file_mark = open(mark_path, 'r')

            side_rate_1 = file_mark.read()
            if abs(float(side_rate_1) - float(side_rate)) == 0:
                result = "Same Side Rate !!!"

            file_mark.close()

            os.remove(mark_path)

            return result
        else:
            return "Fail !"
def u_checkin_upload1(class_name, name, lng, lat):
    """Attention:

        Now stipulate that Only Two Photos will be uploaded
            And This api used for the first photo uploaded

    :return:

    """

    file_stream = request.form.get("image01")

    base64_data_bytes = file_stream.encode("utf-8")
    base64_decode = base64.b64decode(base64_data_bytes)

    dirpath = '/var/www/demoapp'

    pic_file_type = 'jpeg'

    filename = name + "upload1" + '.' + pic_file_type

    move_to_path = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG" + '/' + filename
    image = io.BytesIO(base64_decode)
    img = Image.open(image)
    img.save(move_to_path)

    IP = request.remote_addr

    detector_forcheckin = detector

    sp_forcheckin = sp

    facerec_forcheckin = facerec

    dir_path = '/var/www/demoapp/Accounts'

    dirpath_forcheckin = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG"

    result, side_rate = faceRecognzedProcess(detector_forcheckin,
                                             sp_forcheckin, facerec_forcheckin,
                                             dir_path, class_name, name,
                                             dirpath_forcheckin, filename,
                                             pic_file_type)

    os.remove(dirpath_forcheckin + '/' + filename)

    if result == "Good !":
        mark_path = dir_path + '/' + class_name + '/' + name + '/' + "mark1.txt"
        file_mark = open(mark_path, 'w')
        file_mark.write(str(side_rate) + "-" + str(lng) + "-" + str(lat))
        file_mark.close()

    return result
Exemplo n.º 3
0
def u_checkin_upload1(class_name, name):
    """Attention:

        Now stipulate that Only Two Photos will be uploaded
            And This api used for the first photo uploaded

    :return:

    """
    side_rate = 0

    result = "This is the Original Value of the result !"

    detector_forcheckin = detector

    sp_forcheckin = sp

    facerec_forcheckin = facerec

    dir_path = '/var/www/demoapp/Accounts'

    dirpath_forcheckin = "/var/www/demoapp/student_photo"

    upload_file = request.files['image01']

    if upload_file and allowed_file(upload_file.filename):
        filename = secure_filename(upload_file.filename)

        upload_file.save(
            os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename))

        result, side_rate = faceRecognzedProcess(
            detector_forcheckin, sp_forcheckin, facerec_forcheckin, dir_path,
            class_name, name, dirpath_forcheckin, upload_file.filename)

        os.remove(dirpath_forcheckin + '/' + upload_file.filename)

    if result == "Good !":
        mark_path = dir_path + '/' + class_name + '/' + name + '/' + "mark1.txt"
        file_mark = open(mark_path, 'w')
        file_mark.write(str(side_rate))
        file_mark.close()

    return result
Exemplo n.º 4
0
def u_checkin_upload2(class_name, name):
    """Attention:

        Now stipulate that Only Two Photos will be uploaded
            And This api used for the first photo uploaded

    :return:

    """
    course_name = request.form.get("course_name")

    teacher_name = request.form.get("teacher_name")

    file_stream = request.form.get("image01")

    base64_data_bytes = file_stream.encode("utf-8")
    base64_decode = base64.b64decode(base64_data_bytes)

    dirpath = '/var/www/demoapp'

    pic_file_type = 'jpeg'

    filename = name + "upload2" + '.' + pic_file_type

    move_to_path = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG" + '/' + filename
    image = io.BytesIO(base64_decode)
    img = Image.open(image)
    img.save(move_to_path)

    detector_forcheckin = detector

    sp_forcheckin = sp

    facerec_forcheckin = facerec

    dir_path = '/var/www/demoapp/Accounts'

    dirpath_forcheckin = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG"

    result, side_rate = faceRecognzedProcess(detector_forcheckin,
                                             sp_forcheckin, facerec_forcheckin,
                                             dir_path, class_name, name,
                                             dirpath_forcheckin, filename,
                                             pic_file_type)

    os.remove(dirpath_forcheckin + '/' + filename)

    if result == "Good !":
        mark_path = dir_path + '/' + class_name + '/' + name + '/' + "mark1.txt"
        if os.path.exists(mark_path):
            file_mark = open(mark_path, 'r')

            side_rate_1 = file_mark.read()
            side_rate_1 = side_rate_1.split("-")

            s_lng = float(side_rate_1[1])
            s_lat = float(side_rate_1[2])

            file_mark.close()

            os.remove(mark_path)

            operation3 = "arouse"
            result_get_lnglat, t_lng, t_lat = get_lng_lat_arouse(
                c, teacher_name, course_name, operation3, conn)

            distance = math.sqrt((t_lng - s_lng) * (t_lng - s_lng) +
                                 (t_lat - s_lat) * (t_lat - s_lat))

            if abs(float(side_rate_1[0]) - float(side_rate)) == 0:
                result = "Same Side Rate !!!"
                return result + str(distance)

            operation2 = "checked"
            insert_student(c, name, course_name, teacher_name, operation2,
                           conn)

            return result + str(distance)
        else:
            return "Fail"
Exemplo n.º 5
0
def u_checkin_upload2_alive_detect(class_name, name):
    """Attention:

        Now stipulate that Only Two Photos will be uploaded
            And This api used for the first photo uploaded

    :return:

    """
    course_name = request.form.get("course_name")

    teacher_name = request.form.get("teacher_name")

    file_stream = request.form.get("image01")

    base64_data_bytes = file_stream.encode("utf-8")
    base64_decode = base64.b64decode(base64_data_bytes)

    dirpath = '/var/www/demoapp'

    pic_file_type = 'jpeg'

    filename = name + "upload2" + '.' + pic_file_type

    move_to_path = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG" + '/' + filename
    image = io.BytesIO(base64_decode)
    img = Image.open(image)
    img.save(move_to_path)

    detector_forcheckin = detector

    sp_forcheckin = sp

    facerec_forcheckin = facerec

    dir_path = '/var/www/demoapp/Accounts'

    dirpath_forcheckin = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG"

    result, side_rate = faceRecognzedProcess(detector_forcheckin,
                                             sp_forcheckin, facerec_forcheckin,
                                             dir_path, class_name, name,
                                             dirpath_forcheckin, filename,
                                             pic_file_type)

    os.remove(dirpath_forcheckin + '/' + filename)

    face_check_left_x_now = side_rate["lip_left_xy"][0]
    # face_check_left_y_now = side_rate["lip_left_xy"][1]
    face_check_right_x_now = side_rate["lip_right_xy"][0]
    # face_check_right_y_now = side_rate["lip_right_xy"][1]

    if result == "Good !":
        mark_path = dir_path + '/' + class_name + '/' + name + '/' + "mark1.txt"
        if os.path.exists(mark_path):
            file_mark = open(mark_path, 'r')

            side_rate_1 = file_mark.read()
            side_rate_1 = side_rate_1.split("-")

            s_lng = float(side_rate_1[1])
            s_lat = float(side_rate_1[2])

            # 这个码,代表着,选用某种模式,比如,1,代表,微笑,识别
            face_check_mode = int(side_rate_1[0])

            # 注意,联,FaceRecognzedProcess.py line 85-107
            face_check_left_x_history = int(side_rate_1[3])
            # face_check_left_y_history = int(side_rate_1[4])
            face_check_right_x_history = int(side_rate_1[5])
            # face_check_right_y_history = int(side_rate_1[6])

            judge_result = False
            if face_check_mode == 1:
                key_points_distance_history = face_check_right_x_history - face_check_left_x_history
                key_points_distance_now = face_check_right_x_now - face_check_left_x_now

                if key_points_distance_now > key_points_distance_history:
                    judge_result = True

            file_mark.close()

            os.remove(mark_path)

            operation3 = "arouse"
            result_get_lnglat, t_lng, t_lat = get_lng_lat_arouse(
                c, teacher_name, course_name, operation3, conn)

            distance = math.sqrt((t_lng - s_lng) * (t_lng - s_lng) +
                                 (t_lat - s_lat) * (t_lat - s_lat))

            if abs(float(side_rate_1[0]) - float(side_rate)) == 0:
                result = "Same_Side_Rate_"
                return result + str(distance)

            if not judge_result:
                return "Face_Fail_" + str(distance)

            operation2 = "checked"
            insert_student(c, name, course_name, teacher_name, operation2,
                           conn)

            return "Good_" + str(distance)
        else:
            return "Face_Fail"
Exemplo n.º 6
0
def u_checkin_upload1(class_name, name, lng1, lat1):
    """Attention:

        Now stipulate that Only Two Photos will be uploaded
            And This api used for the first photo uploaded

    :return:

    """
    course_name = request.form.get("course_name")

    teacher_name = request.form.get("teacher_name")

    operation3 = "arouse"
    result_get_lnglat, t_lng, t_lat = get_lng_lat_arouse(
        c, teacher_name, course_name, operation3, conn)

    if not result_get_lnglat:
        return "No Arousing Yet ! "

    file_stream = request.form.get("image01")

    base64_data_bytes = file_stream.encode("utf-8")
    base64_decode = base64.b64decode(base64_data_bytes)

    dirpath = '/var/www/demoapp'

    pic_file_type = 'jpeg'

    filename = name + "upload1" + '.' + pic_file_type

    move_to_path = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG" + '/' + filename
    image = io.BytesIO(base64_decode)
    img = Image.open(image)
    img.save(move_to_path)

    # Get the client's IP
    # IP = request.remote_addr

    detector_forcheckin = detector

    sp_forcheckin = sp

    facerec_forcheckin = facerec

    dir_path = '/var/www/demoapp/Accounts'

    dirpath_forcheckin = dirpath + "/Accounts/" + class_name + '/' + name + '/' + "OriJPG"

    result, side_rate = faceRecognzedProcess(detector_forcheckin,
                                             sp_forcheckin, facerec_forcheckin,
                                             dir_path, class_name, name,
                                             dirpath_forcheckin, filename,
                                             pic_file_type)

    os.remove(dirpath_forcheckin + '/' + filename)

    if result == "Good !":
        mark_path = dir_path + '/' + class_name + '/' + name + '/' + "mark1.txt"
        file_mark = open(mark_path, 'w')

        # 注意,1,代表,嘴唇判别,模式
        file_mark.write(
            str("1") + "-" + str(lng1) + "-" + str(lat1) + "-" +
            str(side_rate["lip_left_xy"][0]) + "-" +
            str(side_rate["lip_left_xy"][1]) + "-" +
            str(side_rate["lip_right_xy"][0]) + "-" +
            str(side_rate["lip_right_xy"][1]))

        file_mark.close()

        # 注意,之后,这里会,设置,随机函数,同时,check_face_motion 的,数字类型,会更加丰富
        #   “1”,指,微笑
        check_face_motion = "1"

        return check_face_motion
    else:
        return "Fail"