known_faces.append(enc) known_names.append(name) for files in os.listdir("Unknown"): image = face_recognition.load_image_file(f"Unknown/{files}") locations = face_recognition.face_locations(image, model=MODEL) encodings = face_recognition.face_encodings(image, locations) image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) for location, encoding in zip(locations, encodings): res = face_recognition.compare_faces(known_faces, encoding, tolerance=TOLERANCE) match = None if True in res: match = known_names[res.index(True)] print(f"Match: {match}") top_left = (location[3], location[0]) bot_right = (location[1], location[2]) color = [0, 255, 0] cv2.rectangle(image, top_left, bot_right, color, FRAME_THICKNESS) top_left = (location[3], location[2]) bot_right = (location[1], location[2] + 20) cv2.rectangle(image, top_left, bot_right, color, cv2.FILLED) cv2.putText(image, match, (location[3] + 10, location[2] + 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (200, 200, 200), FONT_THICKNESS) cv2.imshow(files, image) cv2.waitkey(0) cv2.destroywindow(files)
def destroyWindow(self): cv2.destroywindow(self._windowName) self._isWindowCreated=False
#Need to work on it code for usb webcamera raspberry pi import cv2 cam = cv2.VideoCapture(0) img = cam.read() cv2.namedwindow("camera", cv2.CV_WINDOW_AUTOSIZE) cv2.imshow("camera", img) cv2.waitKey(0) cv2.destroywindow("camera")
import sys import cv2 ll = '/Users/okhiroyuki/Documents/python/image/Aerial.bmp' img = cv2.imread(ll) cv2.namedWindow("Example1",cv2.WINDOW_AUTOSIZE) cv2.imshow("Example1",img) cv2.waitKey(0) cv2.destroywindow("Example1")
def destroywindow(self): cv2.destroywindow(self.winodwname) slef.iswindowcreated = False