opencv -215:尝试打印人脸坐标时断言失败
opencv -215:Assertion failed while trying to print face coorrdenates
我无法打印面部坐标并出现错误
代码在该行之前工作正常。我尝试通过多种方式修复它,比如使用位置而不是图片名称。
import cv2
trained_face_data= cv2.CascadeClassifier('haarcascade_frontface_default.xml')
# the source pic
img=cv2.imread('D:\opencv\CUTE 2.png')
#img=cv2.imread('CUTE 2.png')
#convert to gray
Gray_img= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face_coordinates = trained_face_data.detectMultiScale(Gray_img)
#showng an image
#cv2.imshow('Clever Programmer Face Detector', Gray_img)
print(face_coordinates)
# wait to excute
cv2.waitKey()
Erroe 消息是
cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-sn_xpupm\opencv\modules\objdetect\src\cascadedetect.cpp:1689: 错误: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
错误原因是什么?
查看训练好的文件名,请:
haarcascade_frontface_default 或 haarcascade_frontalface_default ?
还有你的 xml 文件在哪里?再次检查它的路径。
ProjectFolder
-script.py
-xml file
-im.jpg
import sys
import cv2
pth=sys.path[0] # Returns the "ProjectFolder" path
cs= cv2.CascadeClassifier(pth+'/haarcascade_frontalface_default.xml')
im=cv2.imread(pth+'/im.jpg')
gry= cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
data = cs.detectMultiScale(gry)
print(data)
cv2.waitKey()
它在我的案例中运行良好:
[[ 91 303 573 573]]
我无法打印面部坐标并出现错误
代码在该行之前工作正常。我尝试通过多种方式修复它,比如使用位置而不是图片名称。
import cv2
trained_face_data= cv2.CascadeClassifier('haarcascade_frontface_default.xml')
# the source pic
img=cv2.imread('D:\opencv\CUTE 2.png')
#img=cv2.imread('CUTE 2.png')
#convert to gray
Gray_img= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face_coordinates = trained_face_data.detectMultiScale(Gray_img)
#showng an image
#cv2.imshow('Clever Programmer Face Detector', Gray_img)
print(face_coordinates)
# wait to excute
cv2.waitKey()
Erroe 消息是 cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-sn_xpupm\opencv\modules\objdetect\src\cascadedetect.cpp:1689: 错误: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
错误原因是什么?
查看训练好的文件名,请:
haarcascade_frontface_default 或 haarcascade_frontalface_default ?
还有你的 xml 文件在哪里?再次检查它的路径。
ProjectFolder
-script.py
-xml file
-im.jpg
import sys
import cv2
pth=sys.path[0] # Returns the "ProjectFolder" path
cs= cv2.CascadeClassifier(pth+'/haarcascade_frontalface_default.xml')
im=cv2.imread(pth+'/im.jpg')
gry= cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
data = cs.detectMultiScale(gry)
print(data)
cv2.waitKey()
它在我的案例中运行良好:
[[ 91 303 573 573]]