Beispiel #1
0
 def POST(self):
     data = web.data()
     data = json.loads(data)
     path = data['path']
     im   = Image.open(path).convert('L')
     res  = ''
     if crnnOcr is not None:
         res  = crnnOcr(im)
     return res
Beispiel #2
0
def rec_txt(crop_img):
    H, W = crop_img.shape[:2]
    H2 = 32
    W2 = float(W * H2) / H
    W2 = int(W2)
    size = (W2, H2)
    cv2.resize(crop_img, size, interpolation=cv2.INTER_LINEAR)
    crop_img = Image.fromarray(crop_img)
    text = crnnOcr(crop_img.convert('L'))
    return text
Beispiel #3
0
def crnnRec(im, boxes, leftAdjust=False, rightAdjust=False, alph=0.2, f=1.0):
    """
    crnn模型,ocr识别
    leftAdjust,rightAdjust 是否左右调整box 边界误差,解决文字漏检
    """
    results = []
    im = Image.fromarray(im)
    for index, box in enumerate(boxes):
        degree, w, h, cx, cy = solve(box)
        partImg, newW, newH = rotate_cut_img(im, degree, box, w, h, leftAdjust, rightAdjust, alph)
        text = crnnOcr(partImg.convert('L'))
        if text.strip() != u'':
            results.append({'cx': cx * f, 'cy': cy * f, 'text': text, 'w': newW * f, 'h': newH * f,
                            'degree': degree * 180.0 / np.pi})

    return results
Beispiel #4
0
def crnnRec(im,
            boxes,
            leftAdjust=False,
            rightAdjust=False,
            alph=0.2,
            f=1.0,
            save=True):
    """
    crnn模型,ocr识别
    leftAdjust, rightAdjust 是否左右调整box 边界误差,解决文字漏检
    """
    results = []
    # im = Image.fromarray(im)
    im = Image.fromarray(cv2.cvtColor(im, cv2.COLOR_BGR2RGB))

    for index, box in enumerate(boxes):
        degree, w, h, cx, cy = solve(box)

        # 按照box大小,裁剪图片
        partImg, newW, newH = rotate_cut_img(im, degree, box, w, h, leftAdjust,
                                             rightAdjust, alph)
        # partImg, newW, newH = cut_img = ()
        image_cv = cv2.cvtColor(numpy.asarray(partImg), cv2.COLOR_RGB2BGR)
        cv2.imshow("crnnRec", image_cv)
        # partImg = Image.fromarray(cv2.cvtColor(partImg, cv2.COLOR_BGR2RGB))

        # 图片会转灰度图,进行识别
        # print('crnnRec', partImg.size)
        text, w = crnnOcr(partImg.convert('L'))
        # text, w = crnnOcr(partImg)
        if save:
            image = partImg.resize((w, 32), Image.BILINEAR)
            save_image(image, text)

        # text = crnnOcr(partImg)
        if text.strip() != u'':
            results.append({
                'cx': cx * f,
                'cy': cy * f,
                'text': text,
                'w': newW * f,
                'h': newH * f,
                'degree': degree * 180.0 / np.pi
            })

    return results
Beispiel #5
0
def crnnRec(im,
            boxes,
            leftAdjust=False,
            rightAdjust=False,
            alph=0.2,
            f=1.0,
            tp_groups=None,
            boxAll=None,
            scoreAll=None):
    """
   crnn模型,ocr识别
   leftAdjust,rightAdjust 是否左右调整box 边界误差,解决文字漏检
   """
    results = []
    im = Image.fromarray(im)
    for index, box in enumerate(boxes):
        degree, w, h, cx, cy = solve(box)
        partImg, newW, newH = rotate_cut_img(im, degree, box, w, h, leftAdjust,
                                             rightAdjust, alph)
        text = crnnOcr(partImg.convert('L'))

        detailbox = boxAll[tp_groups[index]]
        detailscore = scoreAll[tp_groups[index]]
        detaildex = tp_groups[index]

        if text.strip() != u'':
            results.append({
                'cx': cx * f,
                'cy': cy * f,
                'text': text,
                'w': newW * f,
                'h': newH * f,
                'degree': degree * 180.0 / np.pi,
                'detailbox': detailbox,
                'detailscore': detailscore,
                'detaildex': detaildex
            })

#degree表示顺时针转多少度.
    return results