Pergunta

I am trying to use the colosift detector provided here: colorDescriptor. I am actually try to call the executable colorDescriptror.exe file from java. I am already run it with bat file and I want just to call the exe from my java code. My code is the following:

Process process = new ProcessBuilder("colorDescriptor.exe", "image.jpg", " --detector densesampling  ","  --ds_spacing 6", " --ds_scales 1.2 ","  --descriptor opponentsift ", " --output out.descr").start();

InputStream is = (InputStream) process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;

The executable is seems to run, but I am getting a error from colorsift code: Warning: no output file to write to. Thus, I am wondering which is the right way to parse my arguments in the executable here.

WORKING COMMAND:

colorDescriptor image.jpg --detector densesampling --ds_spacing 6 --ds_scales 1.2 --descriptor opponentsift   --output out.descr
Foi útil?

Solução

Split the argument pairs into separate arguments without leading and trailing whitespace. For example:

" --detector densesampling  "

should be:

"--detector", "densesampling"

Make the same changes for the other argument pairs. Otherwise, an argument pair as in the posted code will be sent to the underlying program as a single argument, which the program will not recognize.

Outras dicas

Each argument you pass to ProcessBuilder will be an argument passed to the command, for example...

Process process = new ProcessBuilder("colorDescriptor.exe", "image.jpg", " --detector densesampling  ","  --ds_spacing 6", " --ds_scales 1.2 ","  --descriptor opponentsift ", " --output out.descr").start();

Will result in an array of arguments been passed to the executable, resulting in an array with 6 elements in it...

  • "image.jpg"
  • " --detector densesampling "
  • " --ds_spacing 6"
  • " --ds_scales 1.2 "
  • " --descriptor opponentsift "
  • " --output out.descr"

While this might not not seem like much, normally, each space would produce an individual element in the arguments array...

Process process = new ProcessBuilder(
    "colorDescriptor.exe", 
    "image.jpg", 
    "--detector", "densesampling",
    "--ds_spacing", "6", 
    "--ds_scales", "1.2",
    "--descriptor", "opponentsift", 
    "--output", "out.descr").start();

The great thing about ProcessBuilder is you don't need to try an quote or escape spaces, really handy if you need to pass a path that contains spaces.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top