Code Monkey home page Code Monkey logo

Comments (1)

wanghaisheng avatar wanghaisheng commented on August 15, 2024

为了修复 调整ocropus-linegen中读到的文本内容的编码

    print "# reading",text
    with codecs.open(text,'r','utf-8') as stream:
        for line in stream.readlines():
            line = line.strip()
            line = re.sub(args.cleanup,'',line)
            if len(line)<1: continue
            lines.append(line)
print "got",len(lines),"lines"
assert len(lines)>0
lines = list(set(lines))
print "got",len(lines),"unique lines"

修改成

print "# reading",text
with codecs.open(text,'r','utf-8') as stream:
for line in stream.readlines():
line = line.strip()
line = re.sub(args.cleanup,'',line)
line = line.encode('utf-8').strip()
if len(line)<1: continue
lines.append(line)
print "got",len(lines),"lines"
assert len(lines)>0
lines = list(set(lines))
print "got",len(lines),"unique lines"
    os.mkdir(pagedir)
    print "===",pagedir,font
    lineno = 0
    while lineno<args.maxlines:
        reload(sys)
        sys.setdefaultencoding('utf-8')
        (sigma,ssigma,threshold,sthreshold) = pyrandom.choice(degradations)
        sigma += (2*rand()-1)*ssigma
        threshold += (2*rand()-1)*sthreshold
        line = pyrandom.choice(lines) .encode('utf-8')

修改

os.mkdir(pagedir)
print "===",pagedir,font
lineno = 0
while lineno<args.maxlines:
reload(sys)
sys.setdefaultencoding('utf-8')
(sigma,ssigma,threshold,sthreshold) = pyrandom.choice(degradations)
sigma += (2*rand()-1)ssigma
threshold += (2rand()-1)*sthreshold
line = pyrandom.choice(lines)
line = line.encode('utf-8').strip()

为如下

root@4b2648975d03:/ocropy# python pic/ocropus-linegen  -t pic/1-line.txt  -f pic/simsun.ttc -m 1 -o 1-line
fonts ['pic/simsun.ttc']
pic/1-line.txt
# reading pic/1-line.txt
got 1 lines
got 1 unique lines
base 1-line
=== 1-line/pic_simsun pic/simsun.ttc
 0.50  0.50  50 顷3974
root@4b2648975d03:/ocropy# ls -al 1-line/
total 16
drwxr-xr-x  3 root root 4096 May  9 07:41 .
drwxr-xr-x 14 root root 4096 May  9 07:41 ..
drwxr-xr-x  2 root root 4096 May  9 07:41 pic_simsun
-rw-r--r--  1 root root   15 May  9 07:41 pic_simsun.info

from awesome-ocr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.