NameError:未定义名称“ip”

时间:2016-07-16 22:38:04

标签: java python

尝试在imageJ中运行Jython插件时出现语法错误。

Java以

开头
import ij.plugin.filter.PlugInFilter;
import ij.ImagePlus;
import ij.process.ImageProcessor;
import org.python.util.PythonInterpreter;
public class Invert_Filter implements PlugInFilter {
  public int setup(String arg, ImagePlus imp) {
    // inform ImageJ that this plugin filter only handles 8 bit grayscale images
    return DOES_8G;
  }
  public void run(ImageProcessor ip) {
    // create a Python interpreter
    PythonInterpreter py = new PythonInterpreter();
    // pass the image processor of the current image to the Python interpreter
    py.set("ip", ip);
    // execute the Python file containing the source code for this ImageJ plugin filter
    py.execfile("C:\\ImageJ\\plugins\\Invert_Filter.py");
  }
}

和Python代码:

# "ip" is the image processor of the current image that is passed in from ImageJ
ip.invert()

运行时,我得到:

  

NameError:名称'ip'未定义

0 个答案:

没有答案