-1

I'm currently learning Python in spyder software and was just wondering (In reference to my example below) in simplified terms what the sys.argv[1] represents. Is it simply asking for an input?

    import sys

    fn = sys.argv[1]

    filename = os.path.split(fn)[-1].split(".")[0]
    filepath = os.path.split(fn)[0]

    src = cv2.imread(fn)
    # read the image```

>IndexError: list index out of range
lala
  • 47
  • 1
  • 2

1 Answers1

0

sys.argv is a List of Command Line argument.
from the terminal you type: python path/to/your_script.py path/to/the_image.jpg
then the sys.argv List would be: ["path/to/your_script.py", "path/to/the_image.jpg"]
in your case: sys.argv[1] refers to the image file which cv2 should read (ie: "path/to/the_image.jpg").

ibrahem
  • 370
  • 3
  • 12