def modify_frame(frame, clf, clf_th): """ Plot a rectangle and a label if a face is identified in the frame Arguments: ---------- frame: type: numpy.array info: array of frame pixels clf: type: FaceRecognizer object info: trained classifier to identify faces clf_th: type: int / float info: threshold to identify a face as 'Unknown' Returns: ---------- frame: type: numpy.array info: array of frame pixels (may be modified) """ for face, coords in check_faces(frame): face = normalize_face(face) label = clf.predict(face, clf_th) frame = draw_rect(frame, coords) frame = draw_text(frame, label, coords) return frame
def create_dataset(query, pics_num, search_engine=SEARCH_ENGINE): """ Downloads, transforms and stores pictures given a query and an engine Arguments: ---------- query: type: string info: query that fill be plot into the search engine num: type: int info: number of pictures to obtain search_engine: type: dict (optional) info: properties of the search engine to use. Keys: - domain (string) - path (string) - params (dict) """ # Unwrapping search engine properties domain = search_engine['domain'] path = search_engine['path'] params = search_engine['params'] params['q'] = query stored = 0 # Until the number of pictures is not reached while stored < pics_num: if path: url = build_url(domain, path, params) page = get_page(url) path = get_next_page(page, 'fl') params = None # Each image is saved if a face is detected for image in get_images(page, url): for face, _ in check_faces(image): # Normalizes and stores the image face = Image.fromarray(normalize_face(face)) save_image(image=face, output_folder=query.replace(' ', '_'), output_name=str(stored)) stored += 1 if stored == pics_num: break