-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecognition.py
More file actions
57 lines (48 loc) · 1.69 KB
/
recognition.py
File metadata and controls
57 lines (48 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# coding=utf-8
# !/usr/bin/env python
'''
Floodfill sample.
Usage:
floodfill.py [<image>]
Click on the image to set seed point
Keys:
f - toggle floating range
c - toggle 4/8 connectivity
ESC - exit
'''
# Python 2/3 compatibility
from __future__ import print_function
import numpy as np
import cv2 as cv
import sys
import os
from node import Node
def convert(filepath, name):
os.system(
'convert {0} ./recog/{1}/{1}.pbm'.format(filepath, name))
os.system(
'potrace -s ./recog/{0}/{0}.pbm -o ./recog/{0}/{0}.eps'.format(name))
os.system('convert ./recog/{0}/{0}.eps ./recog/{0}/{0}.jpg'.format(name))
os.system('convert ./recog/{0}/{0}.jpg -quality 100 -density 300 ./recog/{0}/{0}_final.tif'.format(name))
def doIntercept(filepath):
models = filepath.split('/')
name = filepath.split('/')[len(models) - 1].split('.')[0]
img = cv.imread(filepath, 1) # 0表示灰度
print(name)
img = cv.GaussianBlur(img, (11, 11), 0)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
outerBox = cv.adaptiveThreshold(gray, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 5, 2)
bw = outerBox # cv.bitwise_and(outerBox)
os.system('mkdir -p ./recog/{0}'.format(name))
cv.imwrite('./recog/{0}/{0}_bw.tif'.format(name), bw)
convert('./recog/{0}/{0}_bw.tif'.format(name), name)
cmd = 'tesseract --tessdata-dir ./lstm/result ./recog/{0}/{0}_final.tif {1}.out -l eng --oem 1 --psm 12'.format(
name,
filepath)
print(cmd)
os.system(cmd)
print(os.popen('cat {0}.out.txt'.format(filepath)).read())
return True
# cv.waitKey(0)
# cv.destroyAllWindows()
doIntercept('/Users/wayne/Documents/tesseract/test/zxl.png')