使用OCR读取圆形文本

使用OCR读取圆形文本

本文介绍了使用OCR读取圆形文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阅读对象上的文字.但是OCR程序无法识别它.当我给出一小部分时,它可以识别.我必须将圆形文本转换为线性文本.我怎样才能做到这一点?谢谢.

I want to read text on the object. But OCR program can't recognize it. When I give the small part, it can recognize. I have to transform circle text to linear text. How can I do this? Thanks.

推荐答案

,您可以将图像从笛卡尔坐标系转换为极坐标系,以准备用于OCR程序的圆路径文本图像.此功能logPolar()可以提供帮助.

you can transform the image from Cartesian coordinate system to Polar coordinate system to prepare circle path text image for OCR program. This function logPolar() can help.

以下是准备圆形路径文本图像的一些步骤:

Here are some steps to prepare circle path text image:

  1. 使用HoughCircles()查找圈子的中心.
  2. 获取均值并进行一些偏移,因此获取中心.
  3. (最佳)从中心裁剪图像的正方形.
  4. 执行logPolar(),然后在必要时旋转它.
  1. Find the circles' centers using HoughCircles().
  2. Get the mean and do some offset, so get the center.
  3. (Optinal) Crop a square of the image from the center.
  4. Do logPolar(), then rotate it if necessary.


检测到圆并获取中心均值并进行偏移后.


After detect circles and get the mean of centers and do offset.

裁剪后的图像:

logPolar()rotate()

此处显示了我的Python3-OpenCV3.3代码,也许有帮助.

My Python3-OpenCV3.3 code is presented here, maybe it helps.

#!/usr/bin/python3
# 2017.10.10 12:44:37 CST
# 2017.10.10 14:08:57 CST
import cv2
import numpy as np

##(1) Read and resize the original image(too big)
img = cv2.imread("circle.png")
img = cv2.resize(img, (W//4, H//4))
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

## (2) Detect circles
circles = cv2.HoughCircles(gray, method=cv2.HOUGH_GRADIENT, dp=1, minDist=3, circles=None, param1=200, param2=100, minRadius = 200, maxRadius=0 )

## make canvas
canvas = img.copy()

## (3) Get the mean of centers and do offset
circles = np.int0(np.array(circles))
x,y,r = 0,0,0
for ptx,pty, radius in circles[0]:
    cv2.circle(canvas, (ptx,pty), radius, (0,255,0), 1, 16)
    x += ptx
    y += pty
    r += radius

cnt = len(circles[0])
x = x//cnt
y = y//cnt
r = r//cnt
x+=5
y-=7

## (4) Draw the labels in red
for r in range(100, r, 20):
    cv2.circle(canvas, (x,y), r, (0, 0, 255), 3, cv2.LINE_AA)
cv2.circle(canvas, (x,y), 3, (0,0,255), -1)

## (5) Crop the image
dr = r + 20
croped = img[y-dr:y+dr+1, x-dr:x+dr+1].copy()

## (6) logPolar and rotate
polar = cv2.logPolar(croped, (dr,dr),80, cv2.WARP_FILL_OUTLIERS )
rotated = cv2.rotate(polar, cv2.ROTATE_90_COUNTERCLOCKWISE)

## (7) Display the result
cv2.imshow("Canvas", canvas)
cv2.imshow("croped", croped)
cv2.imshow("polar", polar)
cv2.imshow("rotated", rotated)

cv2.waitKey();cv2.destroyAllWindows()

这篇关于使用OCR读取圆形文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 11:38