Exemplo n.º 1
0
def get_rectangle_indiviual(image_id, number):
    name = get_face_image_name(image_id, type="rect", full_path=False)
    save_path = fm.get_save_path(image_id)
    res = circumscribe_face(save_path, name[5:], save_path, int(number))
    fullpath = save_path + "/" + name
    with open(fullpath) as f:
        image = f.read()
    content_type = fm.get_content_type(fullpath)
    return put_response(image, content_type=content_type)
Exemplo n.º 2
0
def get_rectangle_indiviual(image_id, number):
    name = get_face_image_name(image_id, type="rect", full_path=False)
    save_path = filemanager.get_save_path(image_id)
    res = circumscribe_face(save_path, name[5:], save_path, int(number))
    fullpath = save_path + "/" + name;
    with open(fullpath) as f:
        image = f.read()
    content_type = filemanager.get_content_type(fullpath)
    return put_response(image, content_type=content_type)
Exemplo n.º 3
0
def upload_file():
    files = request.files
    res = filemanager.upload_file(files)
    if res["status"] == "success":
        name = res["detail"]["name"]
        id = res["detail"]["id"]
        save_path = filemanager.get_save_path(id)
        cutout_res = cutout_face(save_path,name,save_path)
        if cutout_res["status"] == "error":
            return put_response(cutout_res)
        else:
            res["detail"]["faceTotal"] = cutout_res["detail"]["number"]
        circum_res = circumscribe_face(save_path,name,save_path)
        if circum_res["status"] == "error":
            return put_response(circum_res)
    return put_response(res)
Exemplo n.º 4
0
def upload_file():
    files = request.files
    res = fm.upload_file(files)
    if res["status"] == "success":
        name = res["detail"]["name"]
        id = res["detail"]["id"]
        save_path = fm.get_save_path(id)
        cutout_res = cutout_face(save_path, name, save_path)
        if cutout_res["status"] == "error":
            return put_response(cutout_res)
        else:
            res["detail"]["faceTotal"] = cutout_res["detail"]["number"]
        circum_res = circumscribe_face(save_path, name, save_path)
        if circum_res["status"] == "error":
            return put_response(circum_res)
    print(res)
    return put_response(res)
Exemplo n.º 5
0
def get_face_image_name(image_id, type="face", number=0, full_path=True):
    u"""

    return: fullpath name
    """
    prefix = type + "_" + (str(number) + "_" if type == "face" else "")
    path = get_save_path(image_id)
    if path:
        image_list = os.listdir(path)
        for img in image_list:
            if prefix in img:
                name = img
                break
        else:
            return None
        if full_path:
            return os.path.join(path, name)
        else:
            return name
    else:
        return None
Exemplo n.º 6
0
    def get_prob(self, image_id):

        save_path = get_save_path(image_id)
        face_list = [img for img in os.listdir(save_path) if "face_" in img]
        p = {}
        for image_name in face_list:
            _image_num = re.search(r"_\d+_", image_name).group()
            image_num = _image_num[1:][:-1]
            CVimage = cv2.imread(save_path + "/" + image_name)
            image = self.c.shape_CVimage(CVimage)
            with tf.Session() as sess:
                ckpt = tf.train.get_checkpoint_state('./')
                if ckpt:  # checkpointがある場合
                    last_model = ckpt.model_checkpoint_path  # 最後に保存したmodelへのパス
                    self.saver.restore(sess, last_model)  # 変数データの読み込み
                #self.saver.restore(sess, "/root/share/domain/model.ckpt")
                prob = sess.run(self.softmax,
                                feed_dict={
                                    self.images_placeholder: [image],
                                    self.keep_prob: 1.0
                                })[0][0]

            if prob:
                p[image_num] = float(prob)
            else:
                res = {
                    "status": "error",
                    "message": "can not get valid probability",
                }
                return res
        res = {
            "status": "success",
            "data_type": "detail",
            "detail": {
                "probability": p
            }
        }
        return res