相关疑难解决方法(0)

用于 OCR 的 Python OpenCV 歪斜校正

目前,我正在从事一个 OCR 项目,我需要从标签中读取文本(请参见下面的示例图像)。我遇到了图像倾斜问题,我需要帮助修复图像倾斜,以便文本水平而不是倾斜。目前,我正在尝试从给定范围内对不同角度进行评分(下面包含代码)的过程,但这种方法不一致,有时过度校正图像歪斜或平坦无法识别歪斜并纠正它。请注意,在倾斜校正之前,我将所有图像旋转 270 度以使文本直立,然后我通过下面的代码传递图像。传递给函数的图像已经是二进制图像。

代码:


def findScore(img, angle):
    """
    Generates a score for the binary image recieved dependent on the determined angle.\n
    Vars:\n
    - array <- numpy array of the label\n
    - angle <- predicted angle at which the image is rotated by\n
    Returns:\n
    - histogram of the image
    - score of potential angle
    """
    data = inter.rotate(img, angle, reshape = False, order = 0)
    hist = np.sum(data, axis = 1)
    score = np.sum((hist[1:] - hist[:-1]) ** 2)
    return …
Run Code Online (Sandbox Code Playgroud)

python ocr opencv image-processing skew

7
推荐指数
2
解决办法
1万
查看次数

霍夫圆检测精度很低

我试图从一个看起来非常清晰的图像中检测圆形。我确实意识到圆的一部分丢失了,但从我读到的关于霍夫变换的内容来看,这似乎不会导致我遇到的问题。

输入: 输出图像

输出: 在此处输入图片说明

代码:

// Read the image
Mat src = Highgui.imread("input.png");

// Convert it to gray
Mat src_gray = new Mat();
Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);

// Reduce the noise so we avoid false circle detection
//Imgproc.GaussianBlur( src_gray, src_gray, new Size(9, 9), 2, 2 );

Mat circles = new Mat();

/// Apply the Hough Transform to find the circles
Imgproc.HoughCircles(src_gray, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 1, 160, 25, 0, 0);

// Draw the circles detected
for( int i = 0; i < circles.cols(); …
Run Code Online (Sandbox Code Playgroud)

java opencv image-processing computer-vision edge-detection

3
推荐指数
1
解决办法
3678
查看次数