-
-
Save sazio/e7df386adc08551c4913f44ab8989c6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plot faces extracted images | |
def plot_faces_boxes(df, max_cols = 2, max_rows = 6, fsize=(24, 5), max_items=12): | |
idx = 0 | |
for item_idx, item in df.iterrows(): | |
img = cv2.cvtColor(cv2.imread(IMAGES_FOLDER_TRAIN + "/" + item["filename"][:-4] +"/" + item["image"], cv2.IMREAD_UNCHANGED), cv2.COLOR_BGR2RGB) | |
face_img = img #.copy() | |
# grid subplots | |
row = idx // max_cols | |
col = idx % max_cols | |
if col == 0: fig = plt.figure(figsize=fsize) | |
ax = fig.add_subplot(1, max_cols, col + 1) | |
ax.axis("off") | |
# display image with boxes | |
cols = [c for c in df.columns if "boxes" in c] | |
for i, c in enumerate(cols, 0): | |
face_locations = item[c] | |
face_confidence = item[c] | |
if len(face_locations) > 0: | |
for face_location in face_locations: | |
((x,y,w,h), confidence) = face_location | |
# face_img = face_img[y:y+h, x:x+w] | |
cv2.rectangle(face_img, (x, y), (x+w, y+h), (255,i*255,0), 8) | |
cv2.putText(face_img, '%.1f' % (confidence*100.0), (x+w, y+h), cv2.FONT_HERSHEY_SIMPLEX, 2.0, (255,i*255,0), 9, cv2.LINE_AA) | |
ax.imshow(face_img) | |
else: | |
ax.imshow(img) | |
ax.set_title("%s %s / %s - Faces: %d %s %s" % (item["label"] if "label" in df.columns else "", | |
item["filename"], item["image"], | |
item["faces_cv2"] if "faces_cv2" in df.columns else len(face_locations), | |
item["faces_cv2_median"] if "faces_cv2_median" in df.columns else "", | |
item["faces"] if "faces" in df.columns else "")) | |
if (col == max_cols -1): plt.show() | |
idx = idx + 1 | |
if (max_items > 0 and idx >=max_items): break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment