文本检测_opencv_DNN


基于深度学习的文本检测,不是文本识别! https://blog.csdn.net/LuohenYJ
资源截图
代码片段和文件信息
# Import required modules
import cv2 as cv
import math
import argparse

parser = argparse.ArgumentParser(description=‘Use this script to run text detection deep learning networks using OpenCV.‘)
# Input argument
parser.add_argument(‘--input‘ help=‘Path to input image or video file. Skip this argument to capture frames from a camera.‘)
# Model argument
parser.add_argument(‘--model‘ default=“./model/frozen_east_text_detection.pb“
                    help=‘Path to a binary .pb file of model contains trained weights.‘
                    )
# Width argument
parser.add_argument(‘--width‘ type=int default=320
                    help=‘Preprocess input image by resizing to a specific width. It should be multiple by 32.‘
                   )
# Height argument
parser.add_argument(‘--height‘type=int default=320
                    help=‘Preprocess input image by resizing to a specific height. It should be multiple by 32.‘
                   )
# Confidence threshold
parser.add_argument(‘--thr‘type=float default=0.5
                    help=‘Confidence threshold.‘
                   )
# Non-maximum suppression threshold
parser.add_argument(‘--nms‘type=float default=0.4
                    help=‘Non-maximum suppression threshold.‘
                   )

args = parser.parse_args()


############ Utility functions ############
def decode(scores geometry scoreThresh):
    detections = []
    confidences = []

    ############ CHECK DIMENSIONS AND SHAPES OF geometry AND scores ############
    assert len(scores.shape) == 4 “Incorrect dimensions of scores“
    assert len(geometry.shape) == 4 “Incorrect dimensions of geometry“
    assert scores.shape[0] == 1 “Invalid dimensions of scores“
    assert geometry.shape[0] == 1 “Invalid dimensions of geometry“
    assert scores.shape[1] == 1 “Invalid dimensions of scores“
    assert geometry.shape[1] == 5 “Invalid dimensions of geometry“
    assert scores.shape[2] == geometry.shape[2] “Invalid dimensions of scores and geometry“
    assert scores.shape[3] == geometry.shape[3] “Invalid dimensions of scores and geometry“
    height = scores.shape[2]
    width = scores.shape[3]
    for y in range(0 height):

        # Extract data from scores
        scoresData = scores[0][0][y]
        x0_data = geometry[0][0][y]
        x1_data = geometry[0][1][y]
        x2_data = geometry[0][2][y]
        x3_data = geometry[0][3][y]
        anglesData = geometry[0][4][y]
        for x in range(0 width):
            score = scoresData[x]

            # If score is lower than threshold score move to next x
            if(score < scoreThresh):
                continue

            # Calculate offset
            offsetX = x * 4.0
            offsetY = y * 4.0
            angle = anglesData[x]

            # Calculate cos and sin of angle
            cosA = math.cos(angle)
            sinA = math.sin(angle)
            h = x0_data[x] + x2_data[x]
            w = x1_data[x] + x3_data[x]

            # Calculate offset

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)