从嘈杂的车牌上分割每个字符 [英] segment each character from noisy number plate

查看:109
本文介绍了从嘈杂的车牌上分割每个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个有关尼泊尔车牌检测的项目,我从车辆ani中检测到我的车牌,但ani歪了车牌,但结果是车牌的图像很吵.

I am doing a project on Nepali Number Plate Detection where I have detected my number plate from the vehicle ani skewed the number plate but the result is a noisy image of number plate.

我想知道如何将每个字符分割出来,以便可以将其发送给检测部分.我尝试这样做,但它只是将第二行中的字符分段了.

I want to know how to segment every character out of it so it could be sent for detection part. I tried doing this but it just segmented the characters from second line.

def segment(image):
    H = 100.
    height, width, depth = image.shape
    imgScale = H/height
    newX,newY = image.shape[1]*imgScale, image.shape[0]*imgScale
    image = cv2.resize(image,(int(newX),int(newY)))

    cv2.imshow("Show by CV2",image)
    cv2.waitKey(0)
    cv2.imwrite("resizeimg.jpg",image)

    idx =0 
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    _,thresh = cv2.threshold(gray,127,255,cv2.THRESH_TOZERO)

    cv2.imshow("thresh",thresh)
    cv2.waitKey(0)

    # gray=cv2.cvtColor(plate,cv2.COLOR_BW2GRAY)
    _,contours,_ = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
    for cnt in contours:
        idx += 1
        x,y,w,h = cv2.boundingRect(cnt)
        roi = image[y:y+h,x:x+w]
        if(w > 10 and h > 10):
            cv2.imwrite(str(idx) + '.jpg', roi)

推荐答案

假设您具有平板的比例,并且可以通过y轴将平板切成两半.从左到右,脱粒图像,morphologyEx图像,轮廓.将其与另一半相同.

Suppose you have the ratio of the plate and you can cut the plate by half by y-axis. From left to right, thresh image, morphologyEx image, contours. Apply the same with the other half.

image = cv2.imread("1.PNG")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_,thresh = cv2.threshold(gray,127,255,cv2.THRESH_TOZERO)
cv2.imshow("thresh",thresh)

element = cv2.getStructuringElement(shape=cv2.MORPH_RECT, ksize=(5, 11))

morph_img = thresh.copy()
cv2.morphologyEx(src=thresh, op=cv2.MORPH_CLOSE, kernel=element, dst=morph_img)
cv2.imshow("morph_img",morph_img)


_,contours,_ = cv2.findContours(morph_img,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
    r = cv2.boundingRect(c)
    cv2.rectangle(image,(r[0],r[1]),(r[0]+r[2],r[1]+r[3]),(0,0,255),2)

cv2.imshow("img",image)

cv2.waitKey(0)
cv2.destroyAllWindows()

分割字符的另一种方法是沿x轴和y轴查找灰度值之和.您可以轻松地看到x轴上有3个峰,这是3个字符,而y轴上有1个峰,这是您的字符所在的位置.

Another way to segment the characters is to find sum of gray values along x-axis and y-axis. You can easily see there are 3 peaks in x-axis which are 3 characters and 1 peak in y-axis that is where your characters located.

这篇关于从嘈杂的车牌上分割每个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆