如何从Matlab调用OCRopus软件或任何冲突的软件?

时间:2014-11-05 17:50:54

标签: matlab shell environment-variables call

直接从OCRopus提示符调用OCR软件Matlab时,直接从shell提示符调用软件时会出现一系列错误:

>> ! gnome-terminal -x bash ./sampleBash.sh

Traceback (most recent call last):
  File "/usr/local/bin/ocropus-gpageseg", line 15, in <module>
    from pylab import *
  File "/usr/lib/pymodules/python2.7/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 156, in <module>
    from matplotlib.cbook import is_string_like
  File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 28, in <module>
    import numpy as np
  File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
    from . import add_newdocs
  File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 18, in <module>
    from .polynomial import *
  File "/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py", line 19, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/__init__.py", line 50, in <module>
    from .linalg import *
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 29, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg
ImportError: /opt/MATLAB/R2012b/sys/os/glnxa64/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3)

其中sampleBash.sh是:

#!/bin/bash -e

FILENAME='testfile.png'
ocropus-gpageseg --usefilename "$FILENAME"

$SHELL

似乎Matlab的环境变量和系统bash shell之间存在冲突。关于如何向OCRopus软件(或任何其他类似软件)发送“干净”shell环境的任何想法?

这不仅限于OCRopus调用,任何与Matlab内部shell调用期间设置的Matlab环境变量冲突的软件都会遇到同样的问题。

感谢。

1 个答案:

答案 0 :(得分:0)

一个不那么干净的解决方案可能是在调用OCRopus软件之前删除冲突变量:

>> ! gnome-terminal -x bash unset OSG_LD_LIBRARY_PATH; unset XAPPLRESDIR; unset XKEYSYMDB; unset LD_LIBRARY_PATH; unset TOOLBOX; unset XFILESEARCHPATH; unset BASEMATLABPATH; ./sampleBash.sh

通过这种方式,在调用OCR软件之前,会从环境中删除OSG_LD_LIBRARY_PATH等变量。