def upload():
    if request.method == 'POST':
        f = request.files['file']

        if not (f and allowed_file(f.filename)):
            return jsonify({
                "error": 1001,
                "msg": "请检查上传的图片类型,仅限于png、PNG、jpg、JPG、bmp"
            })

        current_path = os.path.dirname(__file__)  # 当前文件所在路径

        # 注意:没有的文件夹一定要先创建,不然会提示没有该路径
        upload_path = os.path.join(current_path, 'static/image_input',
                                   'test.jpg')
        f.save(upload_path)

        # time_start = time.time()
        image = cv2.imread(upload_path, 0)
        points = detection_card.getCardPoint(image)
        text = detection_text.getTextLine(image, points)
        result = recognition_words.getWordsResult(text, model)
        # time_end = time.time()
        # recognition_time = time_end - time_start

        return render_template('recognition.html',
                               words=result,
                               filename=secure_filename(f.filename))

    return render_template('index.html')
def recognition(path):
    """
    调用各模块进行识别文字
    :param path: 图片目录路径
    :return: 识别结果和花费时间
    """
    files = [file for file in os.listdir(path)]
    with open('/media/alton/Data/Documents/DataSet/DataFountain/label/valid_1000.csv', 'r') as f:
        result = list(csv.reader(f))
    count = 0
    for name in files:
        try:

            image = cv2.imread(os.path.join(path, name), 0)
            points = detection_card.getCardPoint(image)
            text = detection_text.getTextLine(image, points)
            words = recognition_words.getWordsResult(text)

            for i in range(len(result)):
                if name.split('.jpg')[0] == result[i][0]:
                    for j in range(10):
                        if words[j] == result[i][j+1]:
                            count += 1
        except (RuntimeError, IndexError) as e:
            continue

        print(count / (len(files)*10.0))
示例#3
0
def recognition(path):
    files = [file for file in os.listdir(path)]
    for name in files:

        time_start = time.time()
        image = cv2.imread(os.path.join(path, name), 0)
        points = detection_card.getCardPoint(image)
        text = detection_text.getTextLine(image, points)
        words = recognition_words.getWordsResult(text)
        time_end = time.time()

        # 输出结果,测试使用
        # print('姓名;{name}\n性别:{sex}\n民族:{nation}\n''出生日期:{brith_year}年{brith_month}月{brith_day}日\n'
        #       '住址:{address}\n身份证号码:''{number}\n签证机关:{organization}\n有效期限:{date}'.format(
        #         name=words[0], sex=words[1], nation=words[2], brith_year=words[3], brith_month=words[4],
        #         brith_day=words[5], address=words[6], number=words[7], organization=words[8], date=words[9]))
        # print('------花费时间:{0}----------'.format(time_end - time_start))
    return words