Reputation: 33
Saying my .py
file is in the folder named Source
. I have another folder inside Source
named TestImage
. TestImage
folder contains a file called 1.png
Source
folder is opened in VS Code, and I am using cv2.imread()
to read images. I know if I move 1.png
into folder Source
, I can do cv2.imread("1.png")
. However, what should I do if I want to access 1.png
in folder TestImage
?
Upvotes: 0
Views: 56
Reputation: 38
According to VS Code documentation, the default working directory for defaults to ${workspaceFolder}
(Source
in your case) so that
cv2.imread("TestImage /1.png")
should work.
Upvotes: 0
Reputation: 1411
Assuming the following directory structure...
.
└── Source
├── TestImage
│ └── 1.png
└── main.py
...and you're starting the script with python main.py
.
You should be able to use:
cv2.imread("./TestImage/1.png")
If you are on Windows, then you may want to use \
instead of /
.
Upvotes: 2