python - 使用 Opencv 进行人脸检测
问题描述
我正在使用 haarcascade_fontalface_default.xml 文件进行人脸检测。这是我的代码
import cv2
#load some free trained data on face fontals from opencv(haarcascade)
trained_face_data=cv2.CascadeClassifier('haarcascade_fontalface_default.xml')
#choose an image to detect faces in
img = cv2.imread('ahk.jpg')
#covert color
#ashshak = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#Detect faces
face_coordinates = trained_face_data.detectMultiScale(img)
print(face_coordinates)
#name of the window where the image will show
cv2.imshow('Face detector opencv',img)
#To set the delay time
cv2.waitKey()
print("code completed")
但是当我尝试运行代码时,我一直面临这个错误。任何人都可以帮我找出解决方案吗
这是我的错误:
Traceback (most recent call last):
File "E:/python/opencv/Facedetection.py", line 13, in <module>
face_coordinates = trained_face_data.detectMultiScale(img)
cv2.error: OpenCV(4.3.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
解决方案
推荐阅读
- php - 在 php 中从用户获取文件并将其发送到烧瓶服务器而不保存它
- php - ErrorException (E_ERROR) 试图获取非对象的属性“标题”
- java - 使用我的应用程序连接到 php .htaccess
- html - HTML 嵌套表结构
- ruby-on-rails - Rails - 在配置块内加载自定义异常处理程序时出现问题
- android - 通过下载 URL 显示来自 firebase cloud firestore 的图像
- opencv - 使用航拍多幅图像通过拼接创建马赛克
- c++ - 3D碰撞检测:凸包与凸包,需要位置和法线
- angular - 在角度 8 中调用导出类的问题
- android - 我应该选择哪个视图来预览带有 Kotlin 的 Camera 的真实图片?