小编Sus*_*hil的帖子

Pytesseract 提高 OCR 准确性

我想从 中的图像中提取文本python。为了做到这一点,我选择了pytesseract。当我尝试从图像中提取文本时,结果并不令人满意。我也经历了这个并实现了列出的所有技术。然而,它的表现似乎并不好。

图像:

在此输入图像描述

代码:

import pytesseract
import cv2
import numpy as np

img = cv2.imread('D:\\wordsimg.png')

img = cv2.resize(img, None, fx=1.2, fy=1.2, interpolation=cv2.INTER_CUBIC)

img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

kernel = np.ones((1,1), np.uint8)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)

img = cv2.threshold(cv2.medianBlur(img, 3), 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]

pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
    
txt = pytesseract.image_to_string(img ,lang = 'eng')

txt = txt[:-1]

txt = txt.replace('\n',' ')

print(txt)
Run Code Online (Sandbox Code Playgroud)

输出:

t hose he large form might …
Run Code Online (Sandbox Code Playgroud)

python ocr tesseract python-3.x pytesser

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

根据屏幕亮度更改背景的 alpha 值

我想根据用户的屏幕亮度更改背景图像的亮度。让我用一个简单的例子来证明这一点。

例如,让这些是我的htmlcss文件:

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.hero{
    width: 100%;
    height: 100vh;
    background: linear-gradient(rgba(0,0,0,0.6),rgba(0,0,0,0.6)),url('https://cdn.decorilla.com/online-decorating/wp-content/uploads/2018/10/modern-interior-design-grey-living-room2.png');
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.content{
    width: 50%;
}

.content h1{
    color: #fff;
    text-align: center;
    font-size: 2rem;
}
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="hero">
        <div class="content">
            <h1>My Test Text!</h1>
        </div>
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

只有当用户的屏幕亮度较低时,效果才好。当屏幕亮度增加时,前景不会从背景中突出。相反,对于明亮的屏幕,Analpha0.75 …

html javascript css

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

标签 统计

css ×1

html ×1

javascript ×1

ocr ×1

pytesser ×1

python ×1

python-3.x ×1

tesseract ×1