How to create a script in Ubuntu



  • I need to do a script to run the command below in the terminal several times:

    opencv_createsamples -img toras/toras_00001.jpg -bg negativas/negativas.txt -info positivas1/positivas1.txt -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 100 -bgcolor 0
    

    What will change every time the command runs are these parameters:

    -img toras/toras_00001.jpg
    -info positivas1/positivas1.txt
    

    Where you got 1, turn 2, 3, 4, 5... until 492

    Does anyone have any idea how to do it?

    Making a comparison with C++, I believe it's something like:

    for(int i = 1; i <= 492; i++)
    {
        opencv_createsamples -img "toras/toras_0000"+to_string(i)+".jpg" -bg negativas/negativas.txt -info "positivas"+to_string(i)+"/positivas"+to_string(i)+".txt" -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 100 -bgcolor 0
    }
    

    But I still haven't figured out how to write something like that in bash...



  • Save it!

    First of all you have significant zeros in the nomenclature of your files:

    -img toras/toras_00001.jpg
    

    It's 5 digits, so it's important to keep the 5 digits when your tie goes from 10, 100. Then, the first step, after the loop of repetition, is to define a variable where you store your number of 5 digits.

    Then you make the command call varying the full number.

    for i in {1..492}
    do
        n=`printf "%05.0f" $i`
        opencv_createsamples -img "toras/toras_$n.jpg" -bg "negativas/negativas$i.txt" -info positivas1/positivas1.txt -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 100 -bgcolor 0
    done 
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2