1 场景
在python环境下,使用EAST文本检测器使用OpenCV检测自然场景图像中的文本。
即通过算法,检测标识出来自然图像中的文字区域。
可以检测图像中的文字区域和视频中的文字区域。
之后可以截取文字区域图像,再通过OCR算法,检测出文字的内容。
检测效果如下:
1.png
2 官网
(1)英文官方地址
(2)中文译文地址
(3)源码地址(百度网盘)
源码项目结构:
.
├── images
│ ├── car_wash.png
│ ├── lebron_james.jpg
│ └── sign.jpg
├── frozen_east_text_detection.pb
├── text_detection.py
└── text_detection_video.py
3 依赖
(1)CV2
pip install opencv-python
(2)numpy
pip install numpy
(3)argparse
pip install argparse
4 代码
4.1 识别图片
(1)识别代码text_detection.py
# USAGE
# python text_detection.py --image images/lebron_james.jpg --east frozen_east_text_detection.pb
# import the necessary packages
from imutils.object_detection import non_max_suppression
import numpy as np
import argparse
import time
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", type=str,
help="path to input image")
ap.add_argument("-east", "--east", type=str,
help="path to input EAST text detector")
ap.add_argument("-c", "--min-confidence", type=float, default=0.5,
help="minimum probability required to inspect a region")
ap.add_argument("-w", "--width", type=int, default=320,
help="resized image width (should be multiple of 32)")
ap.add_argument("-e", "--height", type=int, default=320,
help="resized image height (should be multiple of 32)")
args = vars(ap.parse_args())
# load the input image and grab the image dimensions
image = cv2.imread(args["image"])
orig = image.copy()
(H, W) = image.shape[:2]
# set the new width and height and then determine the ratio in change
# for both the width and height
(newW, newH) = (args["width"], args["height"])
rW = W / float(newW)
rH = H / float(newH)
# resize the image and grab the new image dimensions
image = cv2.resize(image, (newW, newH))
(H, W) = image.shape[:2]
# define the two output layer names for the EAST detector model that
# we are interested -- the first is the output probabilities and the
# second can be used to derive the bounding box coordi