Example #1
0
def upload():
    try:
        image = request.files['image'].read()
        eg_processor.process_image(image)
        return send_file('/ekholabs/face-classifier/result/predicted_image.png', mimetype='image/png')
    except Exception as err:
        logging.error('An error has occurred whilst processing the file: "{0}"'.format(err))
        abort(400)
Example #2
0
def upload():
    try:
        image = request.files['image'].read()
        eg_processor.process_image(image)
        return send_file(
            str(pathlib.Path(__file__).parent.parent.parent.absolute()) +
            '/result/predicted_image.png',
            mimetype='image/png')
    except Exception as err:
        logging.error('No pudimos procesar la imagen enviada ' + str(err))
        abort(400)
Example #3
0
def upload():
    try:
        image = request.files.get('image')
        if not image:
            return make_response('Please provide \'image\' for detect.\n', 400)
        filename = str(uuid.uuid4()) + '-' + image.filename
        eg_processor.process_image(image.read(), filename,
                                   app.config.get('model_path'))
        return make_response(jsonify(convert_data(filename)), 200)
    except Exception as err:
        logging.error(
            'An error has occurred whilst processing the file: "{0}"'.format(
                err))
        abort(400)
def upload():
    try:
        image = request.files['image'].read()
        emotions = eg_processor.process_image(image)
        return jsonify(emotions)
    except Exception as err:
        logging.error('An error has occurred whilst processing the file: "{0}"'.format(err))
        abort(400)
Example #5
0
def upload():
    try:
        image = request.files['image'].read()
        emotion = eg_processor.process_image(image)
        return jsonify(emotion)
    except Exception as err:
        logging.error(
            'An error has occurred whilst processing the file: "{0}"'.format(
                err))
        abort(400)
Example #6
0
def classifyImage():
    # image = request.files['image'].read()
    # print(image[:10], "this is image")
    dataUrl = request.form["dataUrl"]
    print("this is data url", dataUrl[:100])
    content = dataUrl.split(';')[1]
    img_encoded = content.split(',')[1]
    body = base64.decodebytes(img_encoded.encode("utf-8"))
    # jsonInfo =
    full_filepath = eg_processor.process_image(body)

    return render_template(CLASSIFY_IMAGE_TEMPLATE, result_img=full_filepath)
Example #7
0
def upload():
    try:
        image = request.files['image'].read()
        emotion_text = eg_processor.process_image(image)
    except Exception as e:
        logging.error(traceback.format_exc())
        return make_response(
            jsonify({
                'error':
                'An error has occurred whilst processing the file: "{0}"'.
                format(e)
            }), 500)
        #logging.error('An error has occurred whilst processing the file: "{0}"'.format(e))
        #abort(400)
    else:
        return make_response(jsonify({'emotion': emotion_text}), 200)
Example #8
0
def upload(ret_type):
    try:
        # with open('/tmp/debug.txt', "w+") as debug_file:
        #     print("bp A".format(), file=debug_file)
        image = request.files['image'].read()
        result_path = '/tmp/result.png'
        ret_array = eg_processor.process_image(image, result_path)
        if ret_type == 'label':
            return jsonify(ret_array)
        elif ret_type == 'mark':
            return send_file(result_path, mimetype='image/png')
        else:
            return 'unknown ret_type ' + ret_type
    except Exception as err:
        logging.error(
            'An error has occurred whilst processing the file: "{0}"'.format(
                err))
        abort(400)
Example #9
0
def upload():
    try:
        image = ''
        if 'application/json' in request.content_type:
            image = base64.b64decode(request.get_json()['image'])
        elif 'multipart/form-data' in request.content_type:
            image = request.files['image'].read()
        else:
            image = base64.b64decode(request.get_data())
        faces = eg_processor.process_image(image)

        response = make_response(jsonify(faces), 200)
        response.headers['Content-Type'] = 'application/json'
        return response
    except Exception as err:
        logging.error(
            'An error has occurred whilst processing the file: "{0}"'.format(
                err))
        abort(400)
Example #10
0
    def upload():
        """
            上传图片,并返回识别结果
        :return:
        """
        res = dict()
        res['data'] = 1

        filename = photos.save(request.files['photo'])
        # 获取原始图片
        unchanged_image = cv2.imread(UPLOAD_DIR + "/" + filename)

        # 获取情绪,性别信息
        face_size, gender, emotion = eg_processor.process_image(
            unchanged_image)

        results = []
        # 面部特征结果
        face_detail = list()
        face_detail_dict = apply(unchanged_image)
        print(face_detail_dict.keys())
        for k in face_detail_dict.keys():
            face_detail.append(
                Node(contents=[
                    face_detail_dict[k]['type'] + "\n" +
                    face_detail_dict[k]['detail']
                ],
                     dtype="text",
                     style="padding-top:10px").to_dict())

        result = Result(title="面部特征",
                        detail=Node(contents=face_detail).to_dict()).to_dict()
        results.append(result)

        # 健康特征结果
        health_detail = list()
        health_detail.append(
            Node(style="padding-top:10px",
                 dtype="text",
                 contents=["1. 保健原则:益气固表,健脾和胃"]).to_dict())
        health_detail.append(
            Node(style="padding-top:10px",
                 dtype="text",
                 contents=["2. 起居养生:早睡早起,保证睡眠充足,四季起居有常;适度运动,避免过度体力劳动."
                           ]).to_dict())
        health_detail.append(
            Node(style="padding-top:10px",
                 dtype="text",
                 contents=[
                     "3. 饮食药膳:现在是小满,我国古代将小满分为三候:\n“一候苦菜秀;二候靡草死;\
        三候麦秋至。”《周书》中,即有“小满之日苦菜秀”之说。小满时节的气候较为潮湿,所以适宜食用一些祛湿类的食物,如番茄,西瓜。"
                 ]).to_dict())
        health_detail.append(
            Node(dtype="image",
                 contents=["/images/baidu/fanqie.jpeg"]).to_dict())
        health_detail.append(
            Node(dtype="text",
                 contents=[
                     "这是最好的防晒食物。番茄富含抗氧化剂番茄红素,每天摄入16毫克番茄红素可将晒伤的危险系数下降40%。"
                 ]).to_dict())
        health_detail.append(
            Node(dtype="image",
                 contents=["/images/baidu/xigua.jpg"]).to_dict())
        health_detail.append(
            Node(dtype="text",
                 contents=["西瓜含水量在水果中是首屈一指的,所以特别适合补充人体水分的损失。"]).to_dict())

        health_result = Result(
            title="健康状况:气虚,肾虚",
            more="详细诊断 >",
            detail=Node(contents=health_detail).to_dict()).to_dict()
        results.append(health_result)

        res['face_size'] = face_size
        res['results'] = results
        res['image_url'] = photos.url(filename)

        story_json = json.dumps(res)

        openid = request.args.get("openid")
        print(openid)
        if openid is not None:
            # 保存记录到数据库
            print("保存用户记录到数据库" + openid)
            print(UserInfo.query.all())
            user_info = UserInfo.query.filter_by(openid=openid).first()
            print(user_info)
            if user_info is not None:
                story = FaceStory(openid, user_info.nick_name,
                                  user_info.avatar_url, story_json)
                db.session.add(story)
                db.session.flush()
                db.session.refresh(story)
                db.session.commit()
                return Response(json.dumps(story.to_dict()),
                                mimetype='application/json')

        return Response(story_json, mimetype='application/json')