使用tesseract识别板上文本的问题

问题描述

我需要一只手才能使用 opencv 修复我的项目,其中包括检测板块并使用 tesseract 来推断内容,但我不明白为什么只有写在白色背景上的文本才能检测到我,而不是什么时候检测到我我用的是真正的盘子。我试图排列图像以使其更清晰,并且可能只将欧洲车牌的白色部分框起来以简化文本的推断,但我不能只隔离白色。我用的是树莓派 4,不知道有没有用 有人可以帮助我吗?非常感谢。

print("Aspetta 5 secondi per catturare l'immagine,oppure premi <space> per scattare...")

    cam = cv2.VideoCapture(0)  

    num_frames = 0
    while True:
        ret,image = cam.read()
        if not ret:
            print("La webcam non funziona...")
            sys.exit(1)

        cv2.imshow('image',image)

    # Catturo l'immagine se premo <space>
        if (cv2.waitKey(1) & 0xFF) == ord(' '):
            break

    # Aspetto 5 secondi prima di catturare l'immagine
        num_frames += 1
        if num_frames / 10 == 5:
            break

    cam.release()
    cv2.destroyAllWindows()

    cv2.imwrite("/home/pi/Desktop/Riconoscimento Targa/imagee.jpg",image)
    
    filename = 'imagee.jpg'
    
    img = np.array(Image.open(filename))
    
    img = cv2.resize(img,(600,400) )
    
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    gray = cv2.bilateralFilter(gray,13,15,15) 
    edged = cv2.Canny(gray,30,200) #Perform Edge detection
    
    contours=cv2.findContours(edged.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    contours = imutils.grab_contours(contours)
    contours = sorted(contours,key=cv2.contourArea,reverse = True)[:10]
    screenCnt = None
    
    for c in contours:
# approximate the contour
        peri = cv2.arcLength(c,True)
        approx = cv2.approxPolyDP(c,0.018 * peri,True)
# if our approximated contour has four points,then
# we can assume that we have found our screen
        if len(approx) == 4:
            screenCnt = approx
            break
    
    
    # Masking the part other than the number plate
    mask = np.zeros(gray.shape,np.uint8)
    new_image = cv2.drawContours(mask,[screenCnt],255,-1,)
    new_image = cv2.bitwise_and(img,img,mask=mask)
    
    
    # Now crop
    (x,y) = np.where(mask == 255)
    (topx,topy) = (np.min(x),np.min(y))
    (bottomx,bottomy) = (np.max(x),np.max(y))
    Cropped = gray[topx:bottomx+1,topy:bottomy+1]
    
    
    
    cv2.imwrite("/home/pi/Desktop/Riconoscimento Targa/Da eliminare.jpg",Cropped)
    text = pytesseract.image_to_string(Cropped,config='--psm 11 -l ita')

    return text

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...