繁体   English   中英

应用轮廓后如何从图像中提取文本

[英]how to extract text from image after applying contouring

我正在尝试从车牌图像中获取信件,因为我拍摄了一张图像并将其更改为灰色,然后对其应用了阈值。 然后使用轮廓裁剪仅具有牌照的图像。为此,我使用python

码:

import numpy as np
import sys
import cv2
import imutils

img = "d1.jpg"
# load the image and convert it to grayscale
image = cv2.imread(img)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

(T, threshInv) = cv2.threshold(gray, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
cv2.imshow("Threshold", threshInv)

#masking
mask = np.zeros(image.shape[:2], dtype="uint8")

# find all contours in the image and draw ALL contours on the image
cnts=cv2.findContours(threshInv.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
clone = image.copy()
cv2.drawContours(clone, cnts, -1, (0, 255, 0), 2)
print("Found {} contours".format(len(cnts)))

for cnt in cnts:
    x,y,w,h = cv2.boundingRect(cnt)
    crop = image[y:(y+h),x:(x+w)]
    if(w>300 and h>100 and w<700 and h<500):
        print("detected")
        cv2.imshow('plate',crop)
        cv2.rectangle(mask, (x, y), (x+w, y+h), 255, -1)
        break
cv2.imshow("Mask", mask)
masked = cv2.bitwise_and(clone, clone, mask=mask)
cv2.imshow("Mask Applied to Image", masked)
cv2.waitKey(0)
cv2.destroyAllWindows()

轮廓应用图像可以帮助我实现这一目标。 提前致谢。

我不确定您要做什么:光学字符识别? 如果是的话,您可以尝试Tesseract: https ://www.pyimagesearch.com/2017/07/10/using-tesseract-ocr-python/

以下GitHub链接可能会帮助您了解从图像中提取的文本

https://github.com/anuj-badhwar/Indian-Number-Plate-Recognition-System

它基本上使用pytesseract库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM