Search code examples
stringbashloopsconcatenationsift

concatenate more than 4 string in loop at "match" on SIFT via bash


a moment ago, i looked up SIFT algorithm to process my images..

if you ever using SIFT from http://www.cs.ubc.ca/~lowe/keypoints/ there is an executable file named "match" to get correlation of one to another images..

this is the example..

./match -im1 book.pgm -k1 book.key -im2 scene.pgm -k2 scene.key > out.pgm

so..

i realized that i need to speed up my process using bash script.. to correlate more than two images even if the default "match" only accepted 2 images and 2 keys related on that images.. then..

this is my code..

i = 1 
s = ""

for item in *.key
do
    s += "-im$((i)) ${item%.*}.pgm -k$((i++)) $item"
done

./match s > out.pgm

And now the scenario,

based on my code,

if I used echo in line 6

echo "-im$((i)) ${item%.*}.pgm -k$((i++)) $item"

and commented the last line

#! ./match s > out.pgm

then I got the list that I wanted..

BUT..

if I exactly run my code {based on the answers which I commented} there is a problem that faced in my terminal window

Error: Invalid command line argument: -im3

are there can help me please?? ^^

i am so sorry if my English bad..


Solution

  • after I check the "match" code in file match.c in line 32 until 52

    /* Parse command line arguments and read given files.  The command
       line must specify two input images and two files of keypoints
       using command line arguments as follows:
          match -im1 i1.pgm -k1 k1.key -im2 i2.pgm -k2 k2.key > result.v
    */
    while (++arg < argc) {
      if (! strcmp(argv[arg], "-im1")) 
    im1 = ReadPGMFile(argv[++arg]);
      else if (! strcmp(argv[arg], "-im2")) 
    im2 = ReadPGMFile(argv[++arg]);
      else if (! strcmp(argv[arg], "-k1"))
    k1 = ReadKeyFile(argv[++arg]);
      else if (! strcmp(argv[arg], "-k2"))
    k2 = ReadKeyFile(argv[++arg]);
      else
    FatalError("Invalid command line argument: %s", argv[arg]);
    }
    if (im1 == NULL || im2 == NULL || k1 == NULL || k2 == NULL)
      FatalError("Command line does not specify all images and keys.");
    FindMatches(im1, k1, im2, k2);
    exit(0);
    

    at http://www.cs.ubc.ca/~lowe/keypoints/siftDemoV4.zip

    I should add some variables in that codes or use a collection to complemented all variables.. cause my real codes is in Java.. (^^)9

    anyway.. thanks for the answer at bash script.. all of the answer is usefull.. (^^)v