-
-
Save radames/effc25355c194bd23bbd1d0cbf87d449 to your computer and use it in GitHub Desktop.
import cv2 | |
cap = cv2.VideoCapture(0) | |
cap.set(3, 640) # WIDTH | |
cap.set(4, 480) # HEIGHT | |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") | |
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_eye.xml") | |
while(True): | |
# Capture frame-by-frame | |
ret, frame = cap.read() | |
# Our operations on the frame come here | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
faces = face_cascade.detectMultiScale(gray, 1.3, 5) | |
print(len(faces)) | |
# Display the resulting frame | |
for (x, y, w, h) in faces: | |
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2) | |
roi_gray = gray[y:y+h, x:x+w] | |
roi_color = frame[y:y+h, x:x+w] | |
eyes = eye_cascade.detectMultiScale(roi_gray) | |
for (ex, ey, ew, eh) in eyes: | |
cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2) | |
cv2.imshow('frame', frame) | |
k = cv2.waitKey(1) | |
if k == ord('q') or k == 27: | |
break | |
# When everything done, release the capture | |
cap.release() | |
cv2.destroyAllWindows() |
opencv ❯ python3 face_detection.py
[1] 11302 segmentation fault python face_detection.py
Anyone plz HELP ME...
I'm develop in Mac OS X 10.14.6, Python 3.7.4, openCV 4.1.0
Traceback (most recent call last):
File "D:/Python opencv/detect.py", line 15, in
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
error: C:\build\2_4_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\color.cpp:3783: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
help!!!!!!!!
@prashant00797, See this. I think there's someone with the same error as
https://stackoverflow.com/questions/30506126/open-cv-error-215-scn-3-scn-4-in-function-cvtcolor
folks, the assertions error
...cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'
is mostly because your now initiating the CascadeClassifier
with the correct haarcascade path , for example os OSX using Brew and opencv you can:
face_cascade = cv2.CascadeClassifier('/usr/local/Cellar/opencv/4.1.0_2/share/opencv4/haarcascades/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('/usr/local/Cellar/opencv/4.1.0_2/share/opencv4/haarcascades/haarcascade_eye.xml')
or just download the xml files and put on the path of your script
@insung3511 I'm not sure about that. Make sure the input frame is coming with a correct format. You want to convert the colored RGB frame from the webcam to Gray scale gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
help me!!! present this error
SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set
help me!!! present this error
SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set
Hi @Pusak0816 this is probably an error with the path for the haarcascades, make sure you have it pointing to the right place
I am getting the following error
error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-q0nmoxxv\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
Please help me to solve the problem
hi @Anirudh15376 I'm not sure what the error coming from, but I've build a repository with a env in case you want to try.
https://github.com/radames/python_opencv_camera_haar
I think it could be the path for the haar files you can try modify the first lines to
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_eye.xml")
Why is this error? Please help
error Traceback (most recent call last)
in
----> 1 faces= face_classifier.detectMultiScale(gray, 1.3, 5) #location of feature on face
error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-q0nmoxxv\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
Hi @Rasika-Gulhane the problem is the path for the haar cascades double check if it's correct, or use this new syntax
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_eye.xml")
Yes, working now. Thanks!
practica $ python guardardatos.py
Traceback (most recent call last):
File "guardardatos.py", line 9, in
faceClassif= cv2.CascadeClassifier(cv2.data.haarcascades+'haarcascade_frontalface_default.xml')
AttributeError: 'module' object has no attribute 'data'
hi @Mariela1817 maybe you can try this
pip install opencv-contrib-python
hi i am getting this error:
mouth = mouth_cascade.detectMultiScale(roi_gray)
for (mx, my, mw, mh) in mouth:
cv2.rectangle(roi_color, (mx, my), (mx + mw, my + mh), (0, 0, 0), 2)
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'
and i have already used this code:
mouth_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_mcs_mouth.xml')
but its still not working
Traceback (most recent call last):
File "D:/Python opencv/detect.py", line 15, in
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
error: C:\build\2_4_winpack-bindings-win64-vc14-static\opencv\modules\imgproc\src\color.cpp:3783: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
help!!!!!!!!