允许基于图像处理算法从图像中识别车牌的模块。
KnowYourPlates的Python项目详细描述
知道你的车牌吗
允许基于图像处理算法从图像中识别车牌的模块。在
入门
要求
模块使用几个python包:
- 开源计算机视觉和机器学习软件库
- pytesseract-python的光学字符识别(OCR)工具
- NumPy-科学计算的基础包Python
- imutils-一系列方便的函数,用于实现基本的图像处理功能
- 枕头-Python图像库
- Matplotlib-Python二维打印库,可以在各种硬拷贝格式和跨平台的交互式环境中生成出版物质量的图形
在使用know\u plates软件包之前,请确保已安装好它们:
pip install opencv-contrib-python
pip install pytesseract
pip install numpy
pip install imutils
pip install Pillow
pip install matplotlib
安装
使用python包安装程序pip安装此包:
^{pr2}$用法
要从图像识别车牌,请将此软件包导入项目并使用license_plate_recognition函数,并将图像的路径作为参数。示例代码:
# run.pyimportargparsefromknow_your_platesimportalprap=argparse.ArgumentParser()ap.add_argument("-i","--image",required=True,help="Path to the image")args=vars(ap.parse_args())recognized_text=alpr.license_plate_recognition(args['image'])print(recognized_text)
从命令行调用:
python run.py --image ./example.jpg
美国石油学会
- license_plate_识别(img_path:str,new_size:tuple,bluring_method:Callable,二进制化_method:Callable)):
Automatic license plate recognition algorithm.
Found license plate is stored in ./results/ directiory as license_plate.jpg
Parameters
----------
img_path : str
Path to the image
new_size : tuple of integers
First argument of the tuple is new width, second is the new height of the image
blurring_method : function
Function as an object. Suggested functions from this module: gaussian_blur, median_blur, bilateral_filter
binarization_method : function
Function as an object. Suggested functions from this module: threshold_otsu, adaptive_threshold, canny, auto_canny
Returns
-------
str
Text recognized on the image
模糊和过滤
- gaussian_blur(图像:np.ndarray公司):
Wrapper for OpenCV's Gaussian blur. Image is blurred with (3, 3) kernel.
Parameters
----------
image: numpy.ndarray
Image as numpy array. Should be converted into grayscale.
Returns
-------
numpy.ndarray
Blurred image using Gaussian blur
Contribute
----------
Source: https://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html?highlight=gaussianblur#gaussianblur
- median_blur(图像:np.ndarray公司):
Wrapper for OpenCV's median blur. Aperture linear size for medianBlur is 3.
Parameters
----------
image: numpy.ndarray
Image as numpy array. Should be converted into grayscale.
Returns
-------
numpy.ndarray
Blurred image using median blur
Contribute
----------
Source: https://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html?highlight=medianblur#medianblur
- 双边过滤器(图片:np.ndarray公司):
Wrapper for OpenCV's bilateral filter. Diameter of each pixel neighborhood is 11.
Both filter sigma in the color space and filter sigma in the coordinate space are 17.
Parameters
----------
image: numpy.ndarray
Image as numpy array. Should be converted into grayscale.
Returns
-------
numpy.ndarray
Blurred image using bilateral filter
Contribute
----------
Source: https://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html?highlight=bilateralfilter#bilateralfilter
Tresholding images
- canny(图片:np.ndarray公司,阈值1:int,阈值2:int):
Wrapper for OpenCV's Canny algorithm.
Parameters
----------
image : numpy.ndarray
Image as numpy array
threshold1 : int
Lower value of the threshold
threshold2 : int
Upper value of the threshold
Returns
-------
numpy.ndarray
Binarized image using Canny's algorithm.
Contribute
----------
Source: https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.html
- auto_canny(图片:np.ndarray公司,sigma:float=0.33):
Function automatically sets up lower and upper value of the threshold
based on sigma and median of the image
Parameters
----------
image : numpy.ndarray
Image as numpy array
sigma : float
Returns
-------
numpy.ndarray
Binarized image with Canny's algorithm
Contribute
----------
Source: https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.html
- threshold\u otsu(图片:np.ndarray公司):
Wrapper for OpenCV's Otsu's threshold algorithm.
Parameters
----------
image : numpy.ndarray
Image as numpy array
Returns
-------
numpy.ndarray
Binarized image using Otsu's algorithm.
Contribute
----------
Source: https://docs.opencv.org/master/d7/d4d/tutorial_py_thresholding.html
- 自适应阈值(图像:np.ndarray公司):
Wrapper for OpenCV's adaptive threshold algorithm.
Parameters
----------
image : numpy.ndarray
Image as numpy array
Returns
-------
numpy.ndarray
Binarized image using adaptive threshold.
Contribute
----------
Source: https://docs.opencv.org/master/d7/d4d/tutorial_py_thresholding.html
OCR函数
- ocr(img_路径:str):
Wrapper for Tesseract image_to_string function
Parameters
----------
img_path : str
Path to the image
Returns
-------
str
Text recognized on the image
Contribute
----------
PyTesseract: https://pypi.org/project/pytesseract/
图像处理
- 预处理(图像:np.ndarray公司,新的“大小:元组”,模糊的“方法:可调用”,二值化“方法:可调用):
Resizing, converting into grayscale, blurring and binarizing
Parameters
----------
image : numpy.ndarray
Image as numpy array
new_size : tuple of integers
First argument of the tuple is new width, second is the new height of the image
blurring_method : function
Function as an object. Suggested functions from this module: gaussian_blur, median_blur, bilateral_filter
binarization_method : function
Function as an object. Suggested functions from this module: threshold_otsu, adaptive_threshold, canny, auto_canny
Returns
-------
numpy.ndarray
Preprocessed image.
Contribute
----------
Grayscale conversion: https://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html
Bilateral filter: https://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html
- plate_轮廓(图片:np.ndarray公司):
Finding contours on the binarized image.
Returns only 10 (or less) the biggest rectangle contours found on the image.
Parameters
----------
image : numpy.ndarray
Binarized image as numpy array
Returns
-------
list of numpy.ndarray
List of found OpenCV's contours.
Contribute
----------
Finding contours: https://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=findcontours#findcontours
- crop_图像(原始图像:np.ndarray公司,钢板:np.ndarray公司):
Wrapper for Tesseract image_to_string function
Parameters
----------
img_path : str
Path to the image
Returns
-------
str
Text recognized on the image
Contribute
----------
PyTesseract: https://pypi.org/project/pytesseract/
- prepare\ocr(图像:np.ndarray公司):
Prepares image to the OCR process by resizing and filtering (for noise reduction)
Parameters
----------
image : numpy.ndarray
Image as numpy array
Returns
-------
numpy.ndarray
Image prepaired to the OCR process
Contribute
----------
Resizing: https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#void%20resize(InputArray%20src,%20OutputArray%20dst,%20Size%20dsize,%20double%20fx,%20double%20fy,%20int%20interpolation)
Bilateral filter: https://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html
许可证
知道你的车牌在MIT License下发布。在
- 项目
标签: