Debian Codegraph @

lios/ocr/ocr_engine_gocr.py

raw symbols SCIP
1 #!/usr/bin/python3
2 ###########################################################################
3 # Lios - Linux-Intelligent-Ocr-Solution
4 # Copyright (C) 2015-2016 Nalin.x.Linux GPL-3
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ###########################################################################
19
20 import os
21 import subprocess
22 from lios.ocr.ocr_engine_base import OcrEngineBase
23
24
25 class OcrEngineGocr(OcrEngineBase):
26 name = "Gocr"
27
28 def __init__(self,language=None):
29 self.set_language(language)
30
31 def is_available():
32 if ("/bin/gocr" in subprocess.getoutput("whereis gocr")):
33 return True
34 else:
35 return False
36
37 def ocr_image_to_text(self,file_name):
38 os.system("convert {} /tmp/{}_for_ocr.pnm".format(file_name,file_name.split("/")[-1]))
39 os.system("gocr -i /tmp/{0}_for_ocr.pnm -o /tmp/{0}_output.txt ".format(file_name.split("/")[-1]))
40 os.remove("/tmp/{0}_for_ocr.pnm".format(file_name.split("/")[-1]))
41 try:
42 with open("/tmp/{0}_output.txt".format(file_name.split("/")[-1]),encoding="utf-8") as file:
43 text = file.read().strip()
44 os.remove("/tmp/{0}_output.txt".format(file_name.split("/")[-1]))
45 return text
46 except:
47 return ""
48 def cancel():
49 os.system("pkill convert")
50 os.system("pkill gocr")
51
52
53 def get_available_languages():
54 langs = ["eng"]
55 return langs
56
57 def support_multiple_languages():
58 return False