Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't open "face_detector\deploy.prototxt" in function 'cv::dnn::ReadProtoFromTextFile'

I’m trying to learn python, for detect someone used mask or not.

when i run this code

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()

i got error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

---------------------------------------------------------------------------
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'

i tried searching on google with the same problem, and i got problem in certain file. My python project file is in C:\Users\mfahm\anaconda3\Test. Am I getting the wrong filename?

>Solution :

 You have to make sure that the file face_detector\deploy.prototxt and face_detector\res10_300x300_ssd_iter_140000.caffemodel are in the correct directory, then use 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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading