Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python script cant find folder where files are kept
#1
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?
Quote
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Running script pops up python.exe but blank Beerendar 2 62 1 hour ago
Last Post: Beerendar
  Python 2.7.13 Issue Reading .txt files Properly username1145 3 76 Yesterday, 03:08 PM
Last Post: username1145
  Scanning files to rename other files in the same folder. msd1391 6 161 Mar-11-2019, 07:19 PM
Last Post: msd1391
  Problems parsing /proc folder anddontyoucomebacknomore 2 122 Mar-06-2019, 09:16 PM
Last Post: DeaD_EyE
  Python can't find module installed in anaconda iFunKtion 12 21,721 Mar-06-2019, 05:15 PM
Last Post: jwsmallz
  running python script from shell invoked with os.system("x-terminal-emulator -e /bin/ markhaus 2 183 Feb-21-2019, 11:55 PM
Last Post: markhaus
  Run Python Script From My VPS? digitalmatic7 1 82 Feb-20-2019, 10:09 PM
Last Post: metulburr
  Executing python script from SQL Server agent job getting error msavoy 1 119 Feb-15-2019, 08:37 PM
Last Post: Larz60+
  Accessing Files In A Folder asilverg 1 93 Feb-15-2019, 08:08 AM
Last Post: buran
  Delete directories in folder is not working after folder is updated asheru93 2 92 Feb-13-2019, 12:37 PM
Last Post: asheru93

Forum Jump:


Users browsing this thread: 1 Guest(s)