some webcams need a warmup time, and deliver empty frames on startup. you want to check for that.
also, who said , that cv2.rectangle returns anything ? where did you get that idea ? from SO ?
while cap.isOpened():
s, img = cam.read()
if s == None:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5) #hmm, 5 required neighbours is actually a lot.
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) # if you want colors, don't paint into a grayscale...
cv2.imshow(name, img)
k = cv2.waitKey(0)
if k == 27:
cv2.destroyWindow(name)
break