udacity / dog-project

MIT License
184 stars 899 forks source link

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

Open rabiesofany opened 5 years ago

rabiesofany commented 5 years ago

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 commented 2 years ago

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