错误内容整体如下:
File "F:\pythonCode\opencv\ch06\yuanNetFace.py", line 61, in <module>
faces1 = detector.detect(img1)
cv2.error: OpenCV(4.11.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\
net_impl.cpp:279: error: (-204:Requested object was not found) Layer with requested
id=-1 not found in function 'cv::dnn::dnn4_v20241223::Net::Impl::getLayerData
错误原因:笔者使用的opencv版本为4.11.0,但是face_detection_model为face_detection_yunet_2022mar.onnx,导致不匹配。
解决方法:从网站 https://github.com/opencv/opencv_zoo/tree/master/models/face_detection_yunet
下载新版的人脸检测模型文件。