前提・実現したいこと
openCVで顔認証を行いたい。
発生している問題・エラーメッセージ
cascade file が上手く起動しない
エラーメッセージ
error Traceback (most recent call last)
<ipython-input-40-f635a3ba6ff3> in <module>
----> 1 result = detect_face(face)
2 plt.imshow(result,cmap='gray')
<ipython-input-39-152d8294bf59> in detect_face(img)
3 face_img = img.copy()
4
----> 5 face_rects = face_cascade.detectMultiScale(face_img)
6
7 for (x,y,w,h) in face_rects:
error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
ソースコード 全文
import cv2
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
face=cv2.imread('face.jpg',0)
plt.imshow(face,cmap='gray')
cascade_file_path = 'C:/Users/satoshi/opencv-master/data/haarcascades_frontalface_default.xml'
face_cascade = cv2.CascadeClassifier('cascade_file_path')
def detect_face(img):
face_img = img.copy() face_rects = face_cascade.detectMultiScale(face_img) for (x,y,w,h) in face_rects: cv2.rectangle(face_img, (x,y), (x+w,y+h), (255,255,255), 10) return face_img
result = detect_face(face)
plt.imshow(result,cmap='gray')
該当のソースコード
cascade_file_path = 'C:/Users/satoshi/opencv-master/data/haarcascades_frontalface_default.xml'
face_cascade = cv2.CascadeClassifier('cascade_file_path')
def detect_face(img):
face_img = img.copy() face_rects = face_cascade.detectMultiScale(face_img) for (x,y,w,h) in face_rects: cv2.rectangle(face_img, (x,y), (x+w,y+h), (255,255,255), 10) return face_img
result = detect_face(face)
plt.imshow(result,cmap='gray')
python
試したこと
xmlへのディレクトリが違うのかと思い、パスの修正確認を行ったがダメでした
補足情報(FW/ツールのバージョンなど)
。jupyter notebook
回答1件
あなたの回答
tips
プレビュー