{"action":"opened","issue":{"url":"https://api.github.com/repos/ageitgey/face_recognition/issues/781","repository_url":"https://api.github.com/repos/ageitgey/face_recognition","labels_url":"https://api.github.com/repos/ageitgey/face_recognition/issues/781/labels{/name}","comments_url":"https://api.github.com/repos/ageitgey/face_recognition/issues/781/comments","events_url":"https://api.github.com/repos/ageitgey/face_recognition/issues/781/events","html_url":"https://github.com/ageitgey/face_recognition/issues/781","id":424524956,"node_id":"MDU6SXNzdWU0MjQ1MjQ5NTY=","number":781,"title":"ValueError: operands could not be broadcast together with shapes (2,0) (128,)","user":{"login":"Profiiii","id":45557133,"node_id":"MDQ6VXNlcjQ1NTU3MTMz","avatar_url":"https://avatars1.githubusercontent.com/u/45557133?v=4","gravatar_id":"","url":"https://api.github.com/users/Profiiii","html_url":"https://github.com/Profiiii","followers_url":"https://api.github.com/users/Profiiii/followers","following_url":"https://api.github.com/users/Profiiii/following{/other_user}","gists_url":"https://api.github.com/users/Profiiii/gists{/gist_id}","starred_url":"https://api.github.com/users/Profiiii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Profiiii/subscriptions","organizations_url":"https://api.github.com/users/Profiiii/orgs","repos_url":"https://api.github.com/users/Profiiii/repos","events_url":"https://api.github.com/users/Profiiii/events{/privacy}","received_events_url":"https://api.github.com/users/Profiiii/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-03-23T17:30:24Z","updated_at":"2019-03-23T17:30:24Z","closed_at":null,"author_association":"NONE","body":"* face_recognition version:\r\n* Python version: 3.7.0\r\n* Operating System: MacOS\r\n\r\n### Description\r\nGetting this Error when running the Code:\r\n2019-03-23 18:29:04.706 Python[88243:2136040] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)\r\nTraceback (most recent call last):\r\n  File \"Face_Rec_Webcam.py\", line 59, in <module>\r\n    matches = face_recognition.compare_faces(known_face_encodings, face_encoding)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/face_recognition/api.py\", line 222, in compare_faces\r\n    return list(face_distance(known_face_encodings, face_encoding_to_check) <= tolerance)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/face_recognition/api.py\", line 72, in face_distance\r\n    return np.linalg.norm(face_encodings - face_to_compare, axis=1)\r\nValueError: operands could not be broadcast together with shapes (2,0) (128,) \r\n\r\nIt crashes when recognizing the learned face, don't know whats to do\r\n\r\n### My Code\r\n\r\nimport face_recognition\r\nimport cv2\r\n\r\n# This is a demo of running face recognition on live video from your webcam. It's a little more complicated than the\r\n# other example, but it includes some basic performance tweaks to make things run a lot faster:\r\n#   1. Process each video frame at 1/4 resolution (though still display it at full resolution)\r\n#   2. Only detect faces in every other frame of video.\r\n\r\n# PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam.\r\n# OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this\r\n# specific demo. If you have trouble installing it, try any of the other demos that don't require it instead.\r\n\r\n# Get a reference to webcam #0 (the default one)\r\nvideo_capture = cv2.VideoCapture(0)\r\n\r\n# Load a sample picture and learn how to recognize it.\r\nJustin_image = face_recognition.load_image_file(\"Justin.jpg\")\r\nJustin_face_encoding = face_recognition.face_encodings(Justin_image)\r\n\r\n# Load a second sample picture and learn how to recognize it.\r\nPapa_image = face_recognition.load_image_file(\"papa.jpg\")\r\nPapa_face_encoding = face_recognition.face_encodings(Papa_image)\r\n\r\n# Create arrays of known face encodings and their names\r\nknown_face_encodings = [\r\n    Justin_face_encoding,\r\n    Papa_face_encoding\r\n]\r\nknown_face_names = [\r\n    \"Justin\",\r\n    \"Papa\"\r\n]\r\n\r\n# Initialize some variables\r\nface_locations = []\r\nface_encodings = []\r\nface_names = []\r\nprocess_this_frame = True\r\n\r\nwhile True:\r\n    # Grab a single frame of video\r\n    ret, frame = video_capture.read()\r\n\r\n    # Resize frame of video to 1/4 size for faster face recognition processing\r\n    small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)\r\n\r\n    # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)\r\n    rgb_small_frame = small_frame[:, :, ::-1]\r\n\r\n    # Only process every other frame of video to save time\r\n    if process_this_frame:\r\n        # Find all the faces and face encodings in the current frame of video\r\n        face_locations = face_recognition.face_locations(rgb_small_frame)\r\n        face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)\r\n\r\n        face_names = []\r\n        for face_encoding in face_encodings:\r\n            # See if the face is a match for the known face(s)\r\n            matches = face_recognition.compare_faces(known_face_encodings, face_encoding)\r\n            name = \"Unknown\"\r\n\r\n            # If a match was found in known_face_encodings, just use the first one.\r\n            if True in matches:\r\n                first_match_index = matches.index(True)\r\n                name = known_face_names[first_match_index]\r\n\r\n            face_names.append(name)\r\n\r\n    process_this_frame = not process_this_frame\r\n\r\n\r\n    # Display the results\r\n    for (top, right, bottom, left), name in zip(face_locations, face_names):\r\n        # Scale back up face locations since the frame we detected in was scaled to 1/4 size\r\n        top *= 4\r\n        right *= 4\r\n        bottom *= 4\r\n        left *= 4\r\n\r\n        # Draw a box around the face\r\n        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)\r\n\r\n        # Draw a label with a name below the face\r\n        cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)\r\n        font = cv2.FONT_HERSHEY_DUPLEX\r\n        cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)\r\n\r\n    # Display the resulting image\r\n    cv2.imshow('Video', frame)\r\n\r\n    # Hit 'q' on the keyboard to quit!\r\n    if cv2.waitKey(1) & 0xFF == ord('q'):\r\n        break\r\n\r\n# Release handle to the webcam\r\nvideo_capture.release()\r\ncv2.destroyAllWindows()"}}
{"actor":{"display_login":"Profiiii"}}