I'm using VS Code for Python (anaconda package and OpenCV).
I'm debugging the program (pressing F5) and I'm getting the error below.
code I'm getting the error with
import cv2 as cv
import os
import numpy as np
pathsyn = os.path.realpath("synset_words.txt")
print("path", pathsyn)
syn = open(pathsyn,"r").read().strip().split("\n")
syncls = [r[r.find(" ") +1:] for r in syn]
vid = cv.VideoCapture(0)
net = cv.dnn.readNetFromCaffe("Classifiers/model/bvlc_googlenet.prototxt","Classifiers/model/bvlc_googlenet.caffemodel")
though the both synset_words.txt,AI02.py
files are in the same directory
both are in the same directory
if I modify the code to
pathsyn = os.path.realpath("OpenCV/synset_words.txt")
then it works.
import cv2 as cv
import os
import numpy as np
pathsyn = os.path.realpath("OpenCV/synset_words.txt")
print("path", pathsyn)
syn = open(pathsyn,"r").read().strip().split("\n")
syncls = [r[r.find(" ") +1:] for r in syn]
vid = cv.VideoCapture(0)
net = cv.dnn.readNetFromCaffe("OpenCV/Classifiers/model/bvlc_googlenet.prototxt","OpenCV/Classifiers/model/bvlc_googlenet.caffemodel")
Directories; .vscode is outside of the OpenCV folder
this is because .vscode
the folder is in the previous directory and my AI02.py
and synset_words.txt
is in OpenCV folder.
Directory where VS Code is finding the file (where the .vscode folder also):
C:\Users\user\Documents\Python Scripts
but the file is in (where vs code should direct debugger like terminal):
C:\Users\user\Documents\Python Scripts\OpenCV