0

I have a Java program that reads an image file (.jpg, .bmp, .png )) and creates indices on that file using a clustering algorithm. But the problem is that every time I have to explicitly give the name of that image file, which is to be indexed. What I want is a code that will automatically scan all images present in my Linux system and index them. I found it's possible by shell script but still not getting it.

user unknown
  • 35,537
  • 11
  • 75
  • 121
adi
  • 25
  • 4
  • post script code and what params your java app takes - how do you call it – Adrian Mar 20 '12 at 15:01
  • What do you want to do? Have the shell invoke your program many times with all the images of your system, or have your Java program scan your disk and find by itself all the images? What have you tried so far? – Guillaume Polet Mar 20 '12 at 15:01
  • please consider editing your question to include samples of what you mean by image file, samples of the index created (or at least non-generic descriptions of both). Then we need to see some samples of how your data will be changed by your processing. Finally, you should include some of the code you have tried so far. AND it all should fit neatly within about 50 lines on the screen. Right now, I don't know if you mean image file as in a Windows disk image OR a tif/jpeg image or ???. AND do you mean index on the contents (inside) the file OR just by filename. Good luck. – shellter Mar 20 '12 at 15:03
  • images include .jpg, .bmp or .png files. I want my java program to scan the disk and find by itself all images on my harddisk...... Indexing is done by using R,G,B values of pixels of image,grouping together pixels which are similar in color...using NBS color distance formula – adi Mar 20 '12 at 15:12
  • Answering to comments doesn't really help you get the maximum number of involved users to reply to your problem. As above, **please consider editing your question** so it is logical presentation of your problem. Don't make us spend time helping you define your problem, that's not programming (which is what StackOverflow is here to support). Good luck. – shellter Mar 20 '12 at 15:54

2 Answers2

0

From what I understand, you want to execute an *.sh script through a java program which in turn loops over some files in a folder?

Have you tried something like this:

public void runCmd() throws IOException, InterruptedException {
    String cmd = "/home_dir/./my_shell_script.sh";
    Runtime run = Runtime.getRuntime();
    Process pr = run.exec(cmd);
    pr.waitFor();
}

This only gives a rough idea what you need to do, but you get the gist

KristofMols
  • 3,487
  • 2
  • 38
  • 48
  • But this will work only for folder path which i assign to cmd string....What if I want to read images from whole filesystem?? – adi Mar 20 '12 at 15:20
  • You can pass arguments to your script by adding them to your cmd string just like you do in your shell. if you provide a file to your script, it will work for any file in your filesystem – KristofMols Mar 20 '12 at 15:28
0

You can use find, and pipe its output to your program:

find \( -name "*.jpg" -or -name "*.png" \) -printf "%h/%f\n" | java YourProgram

and read the filenames, including paths, from stdin (assuming none of them contains a newline character).

For the whole filesystem, you would start from the root dir:

find / ...

A better solution, and not too hard to implement, would be, to search the files in a platform neutral manner from your program, and giving it only a starting path. Here is a good solution, you only need to apply a filter for the file types (jpg, png, bmp).

Community
  • 1
  • 1
user unknown
  • 35,537
  • 11
  • 75
  • 121