我正在嘗試學習 python,以檢測是否有人使用過面具。
當我運行這段代碼時
prototxtPath = r"face_detector\deploy.prototxt"
weightsPath = r"face_detector\res10_300x300_ssd_iter_140000.caffemodel"
faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)
maskNet = load_model("mask_detector.model")
print("[INFO] starting video stream...")
vs = VideoStream(src=0).start()
我有錯誤
---------------------------------------------------------------------------
error Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_13672/2145281415.py in <module>
34 prototxtPath = r"face_detector\deploy.prototxt"
35 weightsPath = r"face_detector\res10_300x300_ssd_iter_140000.caffemodel"
---> 36 faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)
37
38 maskNet = load_model("mask_detector.model")
error: OpenCV(4.5.4) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\caffe\caffe_io.cpp:1126: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "face_detector\deploy.prototxt" in function 'cv::dnn::ReadProtoFromTextFile'
我試著用同樣的問題在谷歌上搜索,但我在某些文件中遇到了問題。我的 python 項目文件在C:\Users\mfahm\anaconda3\Test 中。我得到了錯誤的文件名嗎?
你必須確保文件deploy.prototxt
和res10_300x300_ssd_iter_140000.caffemodel
在正確的目錄,然後使用os.path.join
import os
prototxtPath = os.path.join(os.getcwd(), 'face_detector', 'deploy.prototxt')
weightsPath = os.path.join(os.getcwd(), 'face_detector', 'res10_300x300_ssd_iter_140000.caffemodel')
faceNet = cv2.dnn.readNet(prototxtPath, weightsPath)
print("[INFO] starting video stream...")
vs = VideoStream(src=0).start()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句