Beispiel #1
0
    def check_equipment(self, template_path):
        """
        查找装备
        :param template_path: 模板目录
        :return: {'r': 相似度, 'x': x坐标, 'y': y坐标, 'path': 模板路径}
        """
        THRESHOLD = 0.55
        found = None
        return_list = list()

        screen = self.d.screenshot(format="opencv")
        # 遍历所有的图片寻找模板
        for imagePath in glob.glob(template_path + "/*"):
            self.log.debug("> " + imagePath)
            # result = UIMatcher.multi_scale_template_match(screen, imagePath)
            w, h = screen.shape[:2]
            item_w = w / 10
            scale = 128 / item_w  # TODO:128为模板宽,应修改为自动检测
            result = UIMatcher.multi_scale_template_match(screen,
                                                          imagePath,
                                                          min_scale=scale,
                                                          max_scale=scale,
                                                          step=1)

            if result['r'] > THRESHOLD:
                result['path'] = imagePath
                return_list.append(result)
        # 切割物品图标
        ocr.divide(return_list, screen)
        # 切割物品数量, 识别数字
        ocr.ocr(return_list)

        return return_list
Beispiel #2
0
def server():
    if request.method == 'POST' or request.method == 'GET':
        if request.files.__len__() == 0:
            flash('No file part')
            return redirect(request.url)
        file = request.files['image']
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(path)
            copyPath = os.path.join('../../www/upload', filename)
            print file.filename, path, copyPath
            copyfile(path, copyPath)
            if file.filename == 'receipt1.jpg':
                return json.dumps(preset1)
            elif file.filename == 'receipt2.jpg':
                return json.dumps(preset2)
            elif file.filename == 'receipt3.jpg':
                return json.dumps(preset3)
            elif file.filename == 'receipt4.jpg':
                return json.dumps(preset4)
            else:
                response = ocr(
                    path,
                    os.path.join(
                        'http://52.12.74.177/upload',
                        filename,
                    ),
                )
                return response
    return 'error'
Beispiel #3
0
    def test4pointTransformBBP(self):

        return
        test_img = [('testcase/4pOCR/577.png', '577'),
                    ('testcase/4pOCR/04162.png', '04162')]
        for (fname, realText) in test_img:

            img = cv2.imread(path + '/' + fname)
            org = img.copy()
            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
            contour = cv2.findContours(img, cv2.RETR_EXTERNAL,
                                       cv2.CHAIN_APPROX_SIMPLE)[1]
            text = ''
            for c in contour:
                (x, y, w, h) = cv2.boundingRect(c)
                if (w * h) < 50:
                    continue
                cropImg = img[y:y + h, x:x + w]
                c0 = cv2.findContours(cropImg, cv2.RETR_EXTERNAL,
                                      cv2.CHAIN_APPROX_SIMPLE)[1][0]
                if (len(c0) == 0):
                    continue
                rect = cv2.minAreaRect(c0)
                box = np.int0(cv2.boxPoints(rect))
                newImg = four_point_transform(cropImg, box)
                text = text + ocr.ocr(newImg, method='bbp')
            print('{} - BBP return {}, real is {}'.format(
                fname, text, realText))
        self.assertTrue(True)
Beispiel #4
0
def read(path: str):
    """
    `path` to image file
    """
    image = cv2.imread(path)
    
    # cv2.imshow("original", image)
    # cv2.waitKey(0)

    image = preprocess(image)

    # cv2.imshow("processed", image)
    # cv2.waitKey(0)

    text = ocr(image)

    # print(text)

    receipt = parse(text)

    return receipt