Ask Your Question
0

when I run the below code, I take below error. Can you help me ?

asked 2018-10-15 07:59:34 -0500

bayram gravatar image

updated 2018-10-17 11:14:29 -0500

berak gravatar image
import cv2
import numpy as np

image = cv2.imread('yüz1.jpg')

faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

greyImage = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(image,1.1,4)

for(x,y,w,h) in faces :
    cv2.rectangle(image, (x,y), (x+w,y+h),(0,255,0),3)

cv2.imshow('faces', image)
cv2.waitKey(0)
cv2.destroyAllWindows()


"C:\Users\asus\Documents\Python Çalışma\venv\Scripts\python.exe" "C:/Users/asus/Documents/Python Çalışma/İmageProcessing/faceDetection.py"
Traceback (most recent call last):
  File "C:/Users/asus/Documents/Python Çalışma/İmageProcessing/faceDetection.py", line 8, in <module>
    greyImage = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
edit retag flag offensive close merge delete

Comments

2

Add those lines after image=cv2.imread('yuz1.jpg')

if image is None:
    print ( "Check image path\n")
    exit()
LBerger gravatar imageLBerger ( 2018-10-15 08:04:57 -0500 )edit
1

thank you!

bayram gravatar imagebayram ( 2018-10-15 08:12:37 -0500 )edit

please also make sure, to use ascii filenames only here. no unicode allowed !

berak gravatar imageberak ( 2018-10-15 08:17:07 -0500 )edit

But image and code is the same path then it is writing continuous 'Check image path' when I run the code

bayram gravatar imagebayram ( 2018-10-15 08:20:09 -0500 )edit

But image and code is the same path then it is writing continuous 'Check image path' when I run the code

bayram gravatar imagebayram ( 2018-10-15 08:24:09 -0500 )edit

can you help me?

bayram gravatar imagebayram ( 2018-10-15 08:34:19 -0500 )edit

give full path ( and I think you already check that your image is not really empty)

LBerger gravatar imageLBerger ( 2018-10-15 08:36:12 -0500 )edit

let me restore the original error here !

berak gravatar imageberak ( 2018-10-17 11:15:07 -0500 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2018-10-17 10:41:39 -0500

supra56 gravatar image
faces = faceCascade.detectMultiScale(image,1.1,4)
to
faces = faceCascade.detectMultiScale(greyImage,1.1,4)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2018-10-15 07:59:34 -0500

Seen: 275 times

Last updated: Oct 17 '18