Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Error when trying to run # convert BGR image to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #33

Open
rabiesofany opened this issue Jul 12, 2019 · 1 comment

Comments

@rabiesofany
Copy link

I receive this error when trying to run this function to convert images to grayscale, this is not my code, this was provided by Udacity.

convert BGR image to grayscale

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)


error Traceback (most recent call last)
in
1 # convert BGR image to grayscale
----> 2 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

error: OpenCV(4.1.0) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

That is the whole cell in the detecting human's pictures section

import cv2
import matplotlib.pyplot as plt
%matplotlib inline

extract pre-trained face detector

face_cascade = cv2.CascadeClassifier('haarcascades/haarcascade_frontalface_alt.xml')

load color (BGR) image

img = cv2.imread(human_files[3])

convert BGR image to grayscale

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

find faces in image

faces = face_cascade.detectMultiScale(gray)

print number of faces detected in the image

print('Number of faces detected:', len(faces))

get bounding box for each detected face

for (x,y,w,h) in faces:
# add bounding box to color image
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)

convert BGR image to RGB for plotting

cv_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

display the image, along with bounding box

plt.imshow(cv_rgb)
plt.show()

@HelloImJohn
Copy link

Same err here. If you have found the solution I would be very grateful if you could share said code..

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants