How can I properly specify the absolute path with tkinter asking for directory with dialog?

28 Views Asked by At

I'm currently working on my Bachelor's thesis Python script, which I want to use to track particles based on their color from one or more digital images, and then record their coordinates based on their geometric centroids. I'll later use these coordinates to analyze thermography images. So far so good; the tracking part works great, but I'm facing what seems to me like a trivial problem with specifying the absolute path.

Since I want the entire script to run fully automated, it's not an option for me to put the digital images in the project folder to work with relative paths. However, when I have the images saved in a folder on the desktop, the big problem starts:

The absolute path is: C:\Users\Ü\Desktop\Digi_Images

When I specify this path as a string, it doesn't work.

I've already tried the following:

  1. "C:\Users\Ü\Desktop\Digi_Images"
  2. "C:/Users/Ü/Desktop/Digi_Images"
  3. r"C:\Users\Ü\Desktop\Digi_Images"

My last alternative or way out was to use tkinter to ask for a file dialog:

from tkinter import filedialog 
directory = filedialog.askdirectory() 
print(directory)
# Insert the absolute path with the Digital-Images. 
digiImagesDirectory_absPath:str = directory

But that doesn't work either.

For example, the error message with the last attempt reads:

[ WARN:[email protected]] global loadsave.cpp:248 cv::findDecoder imread_('C:/Users/├£/Desktop/Digi_Images\0280.tiff'): can't open/read file: check file path/integrity
Traceback (most recent call last): 
File "C:\Users\Ü\Documents\Development\VSCode\Project_E_SPT\main.py", line 49, in <module> 
observation_Room_coord = observationRoom(digi_Images_absPath_listed[0],img_scale_width,img_scale_height) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
File "C:\Users\Ü\Documents\Development\VSCode\Project_E_SPT\defineObservRoom.py", line 12, in observationRoom 
img_height, img_width, channels = image.shape ^^^^^^^^^^^ 
AttributeError: 'NoneType' object has no attribute 'shape'

I'm grateful for any tips!

Thank you in advance :)

0

There are 0 best solutions below