Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 python script cant find folder where files are kept
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 = []

      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)

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

Traceback (most recent call last):
File "", 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?
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 -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Redircet output of Python script to .txt file gurbhej_singh 5 149 11 hours ago
Last Post: gurbhej_singh
  Delete Lines that Contain Words - Loop through files in a folder - Write to new files dj99 3 189 Yesterday, 06:34 AM
Last Post: heiner55
  Is there any way to convert a python script (with Tkinter module), to a .exe (Windows moste 3 98 May-12-2019, 12:02 PM
Last Post: snippsat
  Package python script which has different libraries as a single executable or script tej7gandhi 1 63 May-11-2019, 08:12 PM
Last Post: keames
  Upload files to Google/Azure/AWS or cloud drives using python tej7gandhi 0 62 May-11-2019, 03:02 PM
Last Post: tej7gandhi
  How to launch a program through python script - Mac OS Mojave Aurimas 2 129 May-11-2019, 10:20 AM
Last Post: kritesh
  Batch file not running python script in task scheduler davork 3 100 May-09-2019, 12:53 PM
Last Post: Gribouillis
  Python script that calls jamfHelper binary kennethdean2010 19 540 May-07-2019, 03:50 PM
Last Post: kennethdean2010
  run python script on startup? korenron 1 90 May-06-2019, 09:18 PM
Last Post: snippsat
  Read a folder with a multiple files NewBeie 7 141 May-06-2019, 08:04 AM
Last Post: NewBeie

Forum Jump:

Users browsing this thread: 1 Guest(s)