Unsuccessfully trying to solve a seemingly simple problem: get dimensions of the image located in a folder using cv2.imread. The folders structure as follow:
Main Folder
-- ...
-- input
-- Data1
-- 001
100.png
101.png
102.png
-- VP_code
-- test.py
Run from within "Main Foder" :
python VP_code/test.py --input_video_url ./input
from "test.py" following codes:
## Detect original image dimention
input_clip_url = os.path.join(opts.input_video_url, test_clip_par_folder, clip_name)
image_folder_path=input_clip_url
image_subfolder_path=os.listdir(image_folder_path)
image_path=cv2.imread(image_subfolder_path[0])
print ("Folder path_"+str(image_folder_path))
print ("Image subfolder path_"+str(image_subfolder_path))
print ("Image path_"+str(image_subfolder_path[0]))
print ("Image read_"+str(image_path))
## End of detect original image dimention
As result it properly detects everything but "imread" :
Folder path_./input/data_1/001
Image subfolder path_['100.png','101.png','102.png']
Image path_100.png
Image read_None
I tried image.open (PIL) - no luck. So,it looks like there is a problem with "path" but I couldn't manage to resolve it. My great appreciation for any suggestions.from test,py
As slothrop comments, cv2.imread needs the full path [or just "correct" part as Christoph commented], not only the file name: if you call the script from the local directory of the image or if you change the current working directory, then it should work with "100.png" etc.
Yes, the parameter in the function is "filename" but it means a full path [or "correct" path], with "full" I mean including the folder component from your segmentation: https://docs.opencv.org/3.4/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56
(Did you try it with code that opens the images with the full path for a sample image, e.g.
print(cv2.imread("c:\\mainfolder\\input\\Data1\\001\\100.png").shape)etc.For the dimensions of the first file:
or:
Also you can use glob.glob and call it with the image_folder_path and a wildcard, "*.png", it will collect a list of full paths for the selected files.
https://docs.python.org/3/library/glob.html