Pyboof: How to use python wrappers in java?

I have downloaded pyboof which are python wrappers in java. So, my question is how exactly can I use them? I wrote a simple program that opens a command shell and runs the wrapper from there. My program is the above:

package alltestshere;
import java.awt.image.BufferedImage;
import java.io.* ;
import boofcv.io.UtilIO;
import boofcv.io.image.UtilImageIO;
public class PythonCaller { public static void main (String [] args) throws IOException { Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("cmd set PATH = C:\\Python27"); Process pr2 = rt.exec("cmd python27 C:\\Users\\Caterina\\Downloads\\PyBoof-master\\PyBoof-master\\examples\\blur_image.py"); Process pr3 = rt.exec("cmd blur_image.py"); } } 

But when I run it nothing happens. I try to run the "blur_image" py file in python shell as well but it just opens the file while I want to see how the picture has changed (the new picture). So, is this a wrong way to use python wrappers or do I have to do something more in order to use the wrappers? The blur_image wrapper can be found here .

2

1 Answer

Script to run python from Java could look like following:

String script = "C:\\Users\\Caterina\\Downloads\\PyBoof-master\\PyBoof-master\\examples\\blur_image.py";
String python_app = "python27"
Process pr = rt.exec(new String[]{python_app, script})

After process run, you need to wait when it finish by doing following:

pr.waitFor()

If script is expected will write some output or read some input, you should read output and write something for it's input.

Following example writes something to the input stream of subprocess:

BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(p.getOutputStream()));
writer.write("something");
writer.newLine();
writer.close();

Nevertheless, PyBoof is a Python wrapper for the computer vision library BoofCV (opposite direction, from Python to call Java) as it written on it's GitHub page and you can use BoofCV library directly from Java.

9

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like