小编Pet*_*r S的帖子

用于 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万
查看次数

OpenCV Python OCR 边框去除预处理

我目前正在开展一个项目,需要处理 OCR 图像。我设置并安装了过滤器,以使 OCR 的工作尽可能简单,但图像的一个方面我不知道如何修复。在包含的图像中,您可以看到我正在尝试阅读的文本(“PRTraining Tissue...”),并且图像周围有一个黑色边框,需要将其删除才能使我的倾斜校正代码正常工作。有没有什么简单的方法可以快速用白色填充这个黑色边框而不影响文本?

未过滤的图像:

在此输入图像描述

过滤后的图像:

在此输入图像描述

我已经编写了一些代码来删除大部分背景,但大黑点仍然保留为边框。包含的代码是我的图像裁剪脚本,它删除了大部分图像黑色边框并尝试尽可能地隔离文本,但不幸的是,它仍然留下相当多的黑色,与我的倾斜校正脚本混淆。

def boarderRemoval(img):
    """
    Takes in a numpy array and crops the image down to isolate the text (Still leaves a small black border that varys from image to image\n
    Vars:\n
    - img <- numpy array of the label\n
    Returns:\n
    - Cropped down image with smaller black borders
    """
    contours, hierarchy = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cnt = contours[0]
    x,y,w,h = cv2.boundingRect(cnt)
    correctedImage = img[y: y + h, x: x + w]

    return …
Run Code Online (Sandbox Code Playgroud)

python opencv image image-processing computer-vision

5
推荐指数
1
解决办法
3136
查看次数

我不断收到 StyleGAN 的断言错误

最近我一直在玩 StyleGAN 并生成了一个数据集,但是当我尝试运行 train.py 时得到以下信息。

2020-01-08 13:33:21.943217: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:34: The name tf.Dimension is deprecated. Please use tf.compat.v1.Dimension instead.

WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:74: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.

WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:128: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

Creating the run dir: results\00003-sgan-datasets-1gpu
Copying files to the run dir
dnnlib: Running training.training_loop.training_loop() on localhost...
WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:97: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.

WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:109: The name tf.set_random_seed is …
Run Code Online (Sandbox Code Playgroud)

python deep-learning tensorflow generative-adversarial-network

5
推荐指数
1
解决办法
1961
查看次数