Python Forum
python script cant find folder where files are kept - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: python script cant find folder where files are kept (/thread-14304.html)



python script cant find folder where files are kept - Shameendra - Nov-23-2018

I am trying to access a folder "frames" which contains image files which i want to open with python. My code is:

import os
       import matplotlib.pyplot as plt
       import cv2
       from matplotlib.widgets import RectangleSelector


      #global constants
      img = None
      tl_list = []
      br_list = []
      object_list = []

      #constants
      image_folder = 'C:/Users/Angel of Darkness/Downloads/Desktop/Thesis/videos/1_05/frames'
      savedir = 'annotations'
      obj = 'red_hat'

      if __name__ == '__main__':
          for n, image_file in enumerate(os.scandir(frames)):
              img = image_file
              fig, ax = plt.subplots(1)
              image = cv2.imread(image_file.path)
              image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
              ax.imshow(image)
              plt.show()


However when I run this in Anaconda virtual environment, i get the following error:

Traceback (most recent call last):
File "trctocsv.py", line 19, in <module>
for n, image_file in enumerate(os.scandir(frames)):
NameError: name 'frames' is not defined


It seems "frames" folder can not be read by my script. Any suggestions how to resolve this?


RE: python script cant find folder where files are kept - ichabod801 - Nov-23-2018

It's not a file scanning problem. You just never defined a variable named frames. You did define a variable named image_folder, which is probably what you want in place of frames on that line.


RE: python script cant find folder where files are kept - Shameendra - Nov-23-2018

I actually figured the problem out on my own after looking carefully. And yes that is the issue. The os.scandir should contain image_folder. Thanks anyways