def set_faces(self, index, num_layers): """ Populates the six faces of the cubie with Face-objects, and assigns the correct color to these. :param index: ID number of the cubie :param numLayers: Number of layers in the cube """ self.faces[0] = Face(PVector(0,0,1)) self.faces[1] = Face(PVector(0,0,-1)) self.faces[2] = Face(PVector(0,1,0)) self.faces[3] = Face(PVector(0,-1,0)) self.faces[4] = Face(PVector(1,0,0)) self.faces[5] = Face(PVector(-1,0,0)) if (index % num_layers == num_layers -1): self.faces[0].set_color("#FFFFFF") # White if (index % num_layers == 0): self.faces[1].set_color("#FFD500") # Yellow if (index % (num_layers ** 2) >= (num_layers * (num_layers - 1))): self.faces[2].set_color("#FF5900") # Orange if (index % (num_layers ** 2) < num_layers): self.faces[3].set_color("#B90000") # Red if (index >= num_layers ** 2 * (num_layers - 1)): self.faces[4].set_color("#009B48") # Green if (index < num_layers ** 2): self.faces[5].set_color("#0045AD") # Blue
def renderImage(): #Google Vision API client = vision.ImageAnnotatorClient() if request.method == 'POST': file = request.files['file'] file.save( os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(file.filename))) with io.open(UPLOAD_FOLDER + file.filename, 'rb') as image_file: content = image_file.read() image = vision.types.Image(content=content) response = client.face_detection(image=image) faces = response.face_annotations likelihood_name = ('DESCONHECIDO', 'MUITO_IMPROVAVEL', 'IMPROVAVEL', 'POSSIVEL', 'PROVAVEL', 'MUITO_PROVAVEL') rostos = [] i = 1 for face in faces: vertices = ([ '({},{})'.format(vertex.x, vertex.y) for vertex in face.bounding_poly.vertices ]) rosto = Face(i, likelihood_name[face.joy_likelihood], likelihood_name[face.sorrow_likelihood], likelihood_name[face.surprise_likelihood], likelihood_name[face.anger_likelihood], vertices) rostos.append(rosto) i = i + 1 #OPEN CV face_classifier = cv.CascadeClassifier( cv.data.haarcascades + 'haarcascade_frontalface_default.xml') image = cv.imread(UPLOAD_FOLDER + file.filename) image_gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY) faces = face_classifier.detectMultiScale(image_gray) for (x, y, w, h) in faces: cv.rectangle(image, (x, y), (x + w, y + h), (255, 0, 0), 2) cv.imwrite(os.path.join(STATIC, file.filename), image) return render_template('resposta.html', rostos=rostos, imagem=file.filename)
def make_person(row): uid = row[0] login = row[1] vectors = json.loads(row[2]) weight = json.loads(row[3]) gender = row[4] age = row[5] multicultural = row[6] person = Person(uid, login, Face(vectors, (gender, age, multicultural))) person.vectors = vectors person.weight = weight return person
def add_face(self, left, top, width, height, confidence, name): """ Add a new face to the list of recognized faces in this image Args: left (float): the left side of the face's bounding box as a fraction of the image width top (float): the top side of the face's bounding box as a fraction of the image height width (float): the width of the face's bounding box as a fraction of the overall image width height (float): the height of the face's bounding box as a fraction of the overall image height confidence (float): the confidence of the face's recognition, from 0 to 100 name (string): the name of the face recognized """ new_face = Face(left, top, width, height, confidence, name) self.recognized_faces.append(new_face)
def initial_triangulation(self): n1 = Edge() n2 = Edge() n3 = Edge() n4 = Edge() p1 = Edge() p2 = Edge() p3 = Edge() p4 = Edge() c1 = Edge() c2 = Edge() self.edges = [n1, n2, n3, n4, p1, p2, p3, p4, c1, c2] topleft = Vertex(Vector(-0.1, 1.1, 0), p2) topright = Vertex(Vector(1.1, 1.1, 0), p1) bottomleft = Vertex(Vector(-0.1, -0.1, 0), p3) bottomright = Vertex(Vector(1.1, -0.1, 0), p4) self.vertices = [topleft, topright, bottomleft, bottomright] self.initial_vertices = [topleft, topright, bottomleft, bottomright] a = Face(p1) b = Face(p2) self.faces = [a, b] n1.setAttributes(topleft, p1, None, n4, n2) n2.setAttributes(bottomleft, p2, None, n1, n3) n3.setAttributes(bottomright, p3, None, n2, n4) n4.setAttributes(topright, p4, None, n3, n1) p1.setAttributes(topright, n1, a, c1, p4) p2.setAttributes(topleft, n2, b, p3, c2) p3.setAttributes(bottomleft, n3, b, c2, p2) p4.setAttributes(bottomright, n4, a, p1, c1) c1.setAttributes(topleft, c2, a, p4, p1) c2.setAttributes(bottomright, c1, b, p2, p3) self.updated = True
def __init__(self, label, clf): self.frame = None self.thread1 = None self.thread2 = None self.stopEvent1 = None self.stopEvent2 = None self.started = None self.captured = None self.label = label self.vs = VideoStream().start() self.fa = Face() self.emotion = Emotion(clf) self.outputPath = None
def remove_vertex(self, v): # TODO: comprobar si es borde # Hacer convexo el resto repetir = True while repetir: repetir = False for edge in v.edges: if edge.border(): pass elif not edge.convex(): # Esta mal, la flipamos edge.flip() repetir = True break if len(v.out_edges) == 4: v.out_edges[0].flip() # Borrar las aristas for edge in v.edges: self.edges.remove(edge) # Borrar las caras for face in v.faces: self.faces.remove(face) # Borrar el vértice self.vertices.remove(v) if v.border(): new_face = None else: #Creamos la nueva cara (en el borde era None) new_face = Face(v.out_edge.next) self.faces.append(new_face) # Arreglar referencias for edge in v.out_edges: e1 = edge.next e2 = edge.twin.prev a = edge.twin.origin e1.face = new_face e2.face = new_face a.out_edge = e1 e1.prev = e2 e2.next = e1 if new_face: self.delaunay_rec(new_face.edges) self.updated = True
def __init__(self): self.f = Face() self.net = get_model(10, True) ckpt = torch.load("weights/arcface.pth", map_location=torch.device("cpu")) self.net.load_state_dict(ckpt) self.net.eval() self.transform = tf.Compose([ tf.Resize((112, 112)), tf.ToTensor(), tf.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]) ]) self.load()
def computeBits(self): bits = [] self.eyes = [] self.faces = [] for image in self.images: face = Face(image) eye = Eye(face.frame, face.canvas, padding=10) eye.draw(face) eye.iris.normalizeIris() self.eyes.append(eye) self.faces.append(face) bits.append(eye.iris.bits_pattern) self.bits = np.array(bits)
def __split_triangle(self, x, y, z, p, t, old_triangle_index): """split side xz in the middle edge contains triangle index of x,y,v """ px = p[x] py = p[y] pz = p[z] xz = pz - px pv = px + 0.5 * xz l = np.where(np.all(p == pv, axis=1))[0] if not l: v = len(p) p = np.append(p, [pv], axis=0) non_conforming_edge = [x, z, v, len(t) - 1] else: v = l[0] non_conforming_edge = [-x, -z, -v, -len(t) + 1] parent_diameter = t[old_triangle_index].diameter parent_index = t[old_triangle_index].index t = np.delete(t, old_triangle_index, 0) t = np.append(t, [ Face([x, y, v], compute_diameter(px, py, pv), parent_diameter, parent_index) ], axis=0) t = np.append(t, [ Face([y, z, v], compute_diameter(py, pz, pv), parent_diameter, parent_index) ], axis=0) return p, t, non_conforming_edge
def loadState(self, jsImages, training, jsPeople): self.training = training self.images = {} for jsImage in jsImages: h = jsImage['hash'].encode('ascii', 'ignore') self.images[h] = Face(np.array(jsImage['rep']), identity=jsImage['identity']) label_ids = [int(o['people_id']) for o in jsPeople] labels = [str(o['label']) for o in jsPeople] self.people = dict(zip(label_ids, labels)) self.le = LabelEncoder().fit(self.people.keys()) if not training: self.trainClassifier()
def add_detected_faces(self, video_id, detected_face_paths, frame_numbers=None, face_clusters=None): ''' @detected_faces: img paths of detected faces. ''' if frame_numbers is None: frame_numbers = [None for f in faces] faces = [] indices = [] pickle_name = self._get_paths_pickle_name(detected_face_paths) if os.path.exists(pickle_name): with open(pickle_name, 'rb') as handle: (faces, indices) = pickle.load(handle) print("successfully loaded pickle file!", pickle_name) else: for i, path in enumerate(detected_face_paths): face = Face(img_path=path, video_id=video_id, frame=frame_numbers[i]) if self._extract_features(face): faces.append(face) indices.append(i) if self.verbose: print('added face ', face.img_path) if len(faces) > self.n_clusters: with open(pickle_name, 'w+') as handle: pickle.dump((faces, indices), handle, protocol=pickle.HIGHEST_PROTOCOL) else: # Just return empty things. print("There were only {} faces in add detected faces".format( len(faces))) return ([], {}, []), [] ids, added_clusters, faces = self._add_faces(faces, face_clusters) for _, cluster in added_clusters.iteritems(): features = [f.features for f in cluster.faces] cluster.cohesion_score = self._cluster_cohesion(features) return (ids, added_clusters, faces), indices
def draw(self): if not self.faces: return if self.angle < 360 and self.angle > (degrees(2*PI)/self.image_count * self.images_added): self.faces.append(Face(self.images[self.images_added], 0, 0, circle_angle=0)) self.images_added += 1 for face in self.faces: x_off = face.w / 2 y_off = face.h / 2 face.x = self.origin.x + (self.diameter / 2) * cos(radians(face.circle_angle)) - x_off face.y = self.origin.y + (self.diameter / 2) * sin(radians(face.circle_angle)) - y_off face.draw() face.circle_angle += self.rotation_speed self.angle += self.rotation_speed
def extract_faces(self): '''Extract the surface faces using an angle between faces. [TODO:DaveP] This is not finished. ''' self.logger.info("========== extract faces ========== ") angle = self.params.angle surface = self.surface self.logger.info("Angle: {0:f}".format(angle)) feature_edges = vtk.vtkFeatureEdges() feature_edges.SetInputData(surface) feature_edges.BoundaryEdgesOff() feature_edges.ManifoldEdgesOff() feature_edges.NonManifoldEdgesOff() feature_edges.FeatureEdgesOn() feature_edges.SetFeatureAngle(angle) feature_edges.Update() boundary_edges = feature_edges.GetOutput() clean_filter = vtk.vtkCleanPolyData() boundary_edges_clean = clean_filter.SetInputData(boundary_edges) clean_filter.Update() cleaned_edges = clean_filter.GetOutput() conn_filter = vtk.vtkPolyDataConnectivityFilter() conn_filter.SetInputData(cleaned_edges) conn_filter.SetExtractionModeToSpecifiedRegions() self.boundary_face_components = {} self.boundary_faces = {} rid = 1 while True: conn_filter.AddSpecifiedRegion(rid) conn_filter.Update() component = vtk.vtkPolyData() component.DeepCopy(conn_filter.GetOutput()) if component.GetNumberOfCells() <= 0: break print("{0:d}: Number of boundary lines: {1:d}".format( rid, component.GetNumberOfCells())) self.boundary_faces[rid] = Face(rid, component) #self.boundary_face_components[rid] = component conn_filter.DeleteSpecifiedRegion(rid) rid += 1
def get_surface_faces(self): '''Get the faces from the surface mesh using the ModelFaceID data array. The faces are vtkPolyData objects with cell data arrays. ''' self.logger.info("========== get_surface_faces ==========") face_ids = self.surface.GetCellData().GetArray( VtkDataNames.ModelFaceID) if face_ids == None: self.logger.error("No ModelFaceID data.") return face_ids_range = 2 * [0] face_ids.GetRange(face_ids_range, 0) min_id = int(face_ids_range[0]) max_id = int(face_ids_range[1]) self.logger.info("Face IDs range: {0:d} {1:d}".format(min_id, max_id)) ## Extract face geometry. # mesh_faces = {} for i in range(min_id, max_id + 1): #print("[Mesh.get_surface_faces] ---------- ID {0:d} ---------".format(i)) threshold = vtk.vtkThreshold() threshold.SetInputData(self.surface) threshold.SetInputArrayToProcess(0, 0, 0, 1, VtkDataNames.ModelFaceID) threshold.ThresholdBetween(i, i) threshold.Update() surfacer = vtk.vtkDataSetSurfaceFilter() surfacer.SetInputData(threshold.GetOutput()) surfacer.Update() mesh_faces[i] = Face(i, surfacer.GetOutput()) #print("Mesh.[get_surface_faces] Face number of points: %d" % mesh_faces[i].GetNumberOfPoints()) #print("Mesh.[get_surface_faces] Face number of cells: %d" % mesh_faces[i].GetNumberOfCells()) #write_surface_mesh("surface", mesh_faces[i], str(i)) #_for i in range(min_id, max_id+1) self.boundary_faces = mesh_faces for fid, face in self.boundary_faces.items(): npts = face.surface.GetNumberOfPoints() ncells = face.surface.GetNumberOfCells() self.logger.info(" id:{0:d} num cells: {1:d}".format( face.model_face_id, ncells))
def detect_embedd(self, images): faces = [] for ind, image in enumerate(images): print("Detecting faces in image {}/{}".format( ind + 1, len(images))) newFaces = [] det_arr, emb_arr = get_faces(image) for fl, enc in zip(det_arr, emb_arr): face = Face() face.img_name = img.fileName face.enc = emb_arr x0, x1, x2, x3 = fl face.bound_box = (x1, x2, x3, x0) face.myFace = img.getImage()[x1:x3, x0:x2] newFaces.append(face) image.faces = np.array(newFaces) faces += newFaces return faces
def __init__(self, start_point, width, depth, height, color): self.color = color p = start_point self.bottom_0 = Point3D(p.x, p.y, p.z) self.bottom_1 = Point3D(p.x + width, p.y, p.z) self.bottom_2 = Point3D(p.x + width, p.y, p.z + depth) self.bottom_3 = Point3D(p.x, p.y, p.z + depth) self.top_0 = Point3D(p.x, p.y + height, p.z) self.top_1 = Point3D(p.x + width, p.y + height, p.z) self.top_2 = Point3D(p.x + width, p.y + height, p.z + depth) self.top_3 = Point3D(p.x, p.y + height, p.z + depth) self.edge_bottom_0 = Edge(self.bottom_0, self.bottom_1) self.edge_bottom_1 = Edge(self.bottom_1, self.bottom_2) self.edge_bottom_2 = Edge(self.bottom_2, self.bottom_3) self.edge_bottom_3 = Edge(self.bottom_3, self.bottom_0) self.edge_vertical_0 = Edge(self.bottom_0, self.top_0) self.edge_vertical_1 = Edge(self.bottom_1, self.top_1) self.edge_vertical_2 = Edge(self.bottom_2, self.top_2) self.edge_vertical_3 = Edge(self.bottom_3, self.top_3) self.edge_top_0 = Edge(self.top_0, self.top_1) self.edge_top_1 = Edge(self.top_1, self.top_2) self.edge_top_2 = Edge(self.top_2, self.top_3) self.edge_top_3 = Edge(self.top_3, self.top_0) self.points = [self.bottom_0, self.bottom_1, self.bottom_2, self.bottom_3, self.top_0, self.top_1, self.top_2, self.top_3] self.edges = [ self.edge_bottom_0, self.edge_bottom_1, self.edge_bottom_2, self.edge_bottom_3, self.edge_vertical_0, self.edge_vertical_1, self.edge_vertical_2, self.edge_vertical_3, self.edge_top_0, self.edge_top_1, self.edge_top_2, self.edge_top_3 ] self.faces = [ Face([self.edge_bottom_0, self.edge_bottom_1, self.edge_bottom_2, self.edge_bottom_3], color), Face([self.edge_top_0, self.edge_top_1, self.edge_top_2, self.edge_top_3], color), Face([self.edge_bottom_0, self.edge_vertical_1, self.edge_top_0.inversed(), self.edge_vertical_0.inversed()], color), Face([self.edge_bottom_1, self.edge_vertical_2, self.edge_top_1.inversed(), self.edge_vertical_1.inversed()], color), Face([self.edge_bottom_2, self.edge_vertical_3, self.edge_top_2.inversed(), self.edge_vertical_2.inversed()], color), Face([self.edge_bottom_3, self.edge_vertical_0, self.edge_top_3.inversed(), self.edge_vertical_3.inversed()], color) ]
def main(): win = GraphWin("Emoji Jawn", 800, 800) win.setCoords(20, 20, 0, 0) face = Face(win, Point(10, 8), 7) wink, meditate, smile, endGame = makeButtons(win) pt = win.getMouse() while not endGame.clicked(pt): if wink.clicked(pt): face.wink() pt = win.getMouse() elif smile.clicked(pt): face.smile() pt = win.getMouse() elif meditate.clicked(pt): face.meditate() pt = win.getMouse() else: pt = win.getMouse()
def getMeanFace(self, buffer): """Smooth the face detection by using a rolling mean window over the last detected best faces. Args: buffer (Buffer): Buffer for the last detected best faces Returns: Face: Mean best face """ # Mean position buffer.addLast(self.best_face) lastFaces = [item for item in buffer.lasts if item] if lastFaces: xm = int(np.mean([face.x for face in lastFaces])) ym = int(np.mean([face.y for face in lastFaces])) wm = int(np.mean([face.w for face in lastFaces])) hm = int(np.mean([face.h for face in lastFaces])) return Face(xm, ym, wm, hm, self.frame, self.canvas) return self.best_face
def __init__(self, point_0, point_1, point_2, point_3, color): self.color = color self.point_0 = point_0 self.point_1 = point_1 self.point_2 = point_2 self.point_3 = point_3 self.edge_0 = Edge(self.point_0, self.point_1) self.edge_1 = Edge(self.point_1, self.point_2) self.edge_2 = Edge(self.point_2, self.point_3) self.edge_3 = Edge(self.point_3, self.point_0) self.points = [self.point_0, self.point_1, self.point_2, self.point_3] self.edges = [self.edge_0, self.edge_1, self.edge_2, self.edge_3] self.faces = [ Face([self.edge_0, self.edge_1, self.edge_2, self.edge_3]) ]
def importOBJ(filename): """Loads a Wavefront OBJ file. """ vertices = [] faces = [] for line in open(filename, "r"): if line.startswith('#'): continue values = line.split() if not values: continue if values[0] == 'v': v = map(float, values[1:4]) vertices.append(PVector(v[0],v[1],v[2])) elif values[0] == 'f': face = Face([]) for v in values[1:]: w = v.split('/') node=vertices[int(w[0])-1] face.nodes.append(node) faces.append(face) return faces
def find_faces(self, image_raw): st = log.get_current_time() faces = [] image_small = cv2.resize( image_raw, (0, 0), fx=settings.RESIZE_FACTOR, fy=settings.RESIZE_FACTOR) bounding_boxes, _ = align.detect_face.detect_face( image_small, self.minsize, self.pnet, self.rnet, self.onet, self.threshold, self.factor) _factor = int(1 / settings.RESIZE_FACTOR) for bb in bounding_boxes: face = Face() face.image_raw = image_raw face.bounding_box = np.zeros(4, dtype=np.int32) img_size = np.asarray(image_small.shape)[0:2] face.bounding_box[0] = np.maximum( bb[0] - self.face_crop_margin / 2, 0) face.bounding_box[1] = np.maximum( bb[1] - self.face_crop_margin / 2, 0) face.bounding_box[2] = np.minimum( bb[2] + self.face_crop_margin / 2, img_size[1]) face.bounding_box[3] = np.minimum( bb[3] + self.face_crop_margin / 2, img_size[0]) cropped = image_small[face.bounding_box[1]:face.bounding_box[3], face.bounding_box[0]:face.bounding_box[2], :] raw_cropped = image_raw[face.bounding_box[1]*_factor:face.bounding_box[3]*_factor, face.bounding_box[0]*_factor:face.bounding_box[2]*_factor, :] face.image = misc.imresize( cropped, (self.face_crop_size, self.face_crop_size), interp='bilinear') face.face_image_raw = misc.imresize( raw_cropped, (self.face_crop_size, self.face_crop_size), interp='bilinear') face.result.timestamp = log.get_current_time() faces.append(face) et = log.get_current_time() log.logging.debug('face num: ' + str(len(faces)) + ' time usage:' + str(et - st) + 'ms') return faces
def m(): #界面对象 vb = Face() #管理员开机界面 vb.printAdminView() if vb.userOperate("login"): return -1 #获取ATM对象 atm = ATM() while True: vb.printSysFunctionView() #等待用户的操作 operate = input("请输入您的操作:") if operate == "1": #开户 atm.createUser() elif operate == "2": print('查询') elif operate == "3": print('取款') elif operate == "4": print('存款') elif operate == "5": print('转账') elif operate == "6": print('改密码') elif operate == "7": print('锁定') elif operate == "8": print('解锁') elif operate == "9": print('补卡') elif operate == "0": print('销户') elif operate == "t": if vb.userOperate("quit"): return -1 time.sleep(1)
def dual(self): """Return the dual of the current DCEL.""" def set_twins(): for edge_idx in range(0, len(dual_dcel.edges), 2): dual_dcel.edges[edge_idx].twin = dual_dcel.edges[edge_idx + 1] dual_dcel.edges[edge_idx + 1].twin = dual_dcel.edges[edge_idx] def set_next_and_previous(): for face in dual_dcel.faces: face_edges = [ edge for edge in dual_dcel.edges if edge.incident_face == face ] for edge in face_edges: if (not edge.get_destination().is_infinity()): edge.nxt = [ e for e in face_edges if e.origin == edge.get_destination() ][0] if (not edge.origin.is_infinity()): edge.prev = [ e for e in face_edges if edge.origin == e.get_destination() ][0] dual_dcel = DCEL() for edge in self.edges: incident_face = dual_dcel.add_face( Face(circumcentre=edge.twin.origin.as_points())) origin = dual_dcel.add_vertex( Vertex(coordinates=edge.incident_face.circumcentre)) dual_edge = HalfEdge(origin=origin, incident_face=incident_face) incident_face.outer_component = dual_edge origin.incident_edge = dual_edge dual_dcel.edges.append(dual_edge) set_twins() set_next_and_previous() return dual_dcel
def create_subdivided_mesh(self, positions, faces, face_type): if face_type == FaceType.QUAD: faces_to_delete = [] faces_to_append = [] for face in faces: faces_to_delete.append(face) sum_of_points = Point(0, 0, 0) corner_indexes = face.to_quad() for corner_index in corner_indexes: sum_of_points += positions[corner_index] face_center = p3 = sum_of_points / 4 positions.append(face_center) i3 = positions.index(p3) # c0 xx c3 # xx p3 xx # c1 xx c2 for i in range(4): p0 = positions[corner_indexes[i]] p1 = (positions[corner_indexes[i]] + positions[corner_indexes[(i + 1) % 4]]) / 2 p2 = (positions[corner_indexes[i]] + positions[corner_indexes[(i - 1) % 4]]) / 2 if p1 not in positions: positions.append(p1) if p2 not in positions: positions.append(p2) i0 = positions.index(p0) i1 = positions.index(p1) i2 = positions.index(p2) faces_to_append.append(Face([i2, i0, i1, i2, i1, i3])) for face in faces_to_delete: faces.remove(face) for face in faces_to_append: faces.append(face) return True, Mesh(positions, faces, face_type) return False, None
def main(): win = GraphWin("Bouncing Face", 500, 500) win.setCoords(100, 100, -100, -100) face = Face(win, Point(0, 0), 15) dx = 5 dy = 5 for i in range(10000): c = face.getCenter() if c.getX() > 80: dx = -5 elif c.getX() < -80: dx = 5 elif c.getY() > 80: dy = -5 elif c.getY() < -80: dy = 5 sleep(0.005) face.move(dx, dy)
def __init__(self, event_json): self.people = [] self.json = event_json self.event_type = event_json["event"] if event_json.get("people"): people_json = event_json["people"] i = 0 while i < len(people_json): person_json = people_json[i] person = Person(person_json) self.people.append(person) i += 1 self.faces = [] if event_json.get("faces"): faces_json = event_json["faces"] i = 0 while i < len(faces_json): face_json = faces_json[i] face = Face(face_json) self.faces.append(face) i += 1
def main(): import os import cv2 from face import Face from recog import Test images = [] for filename in os.listdir('./face_data/s1'): try: img = cv2.imread('./face_data/s1/' + filename) if img is not None: img = img[:, :, 0] images.append(img) except ValueError: print(filename + " is not recognised as image file") except IsADirectoryError: print(filename + " is a directory") Id = input('Enter Id: ') f1 = Face(input('Enter Name: '), Id, images) img = cv2.imread('./face_data/s3/2.pgm') img = img[:, :, 0] t1 = Test(img, Id) print(t1)
def add_triangle_edges(circumcentre): triangles_edges = [] for vertex_idx, origin in enumerate(triangle_vertices): # Destination of the edge in this triangle that has vertex as origin destination = triangle_vertices[(vertex_idx + 1) % 3] edge_1 = HalfEdge(origin) edge_2 = HalfEdge(destination, twin=edge_1) edge_1.twin = edge_2 edge_1 = dcel.add_edge(edge_1) edge_2.twin = edge_1 edge_2 = dcel.add_edge(edge_2) edge_1.twin = edge_2 triangles_edges.append(edge_1) triangle_face = Face(triangles_edges[0], circumcentre=list(circumcentre)) dcel.faces.append(triangle_face) # Set previous and next of the edges for edge_idx, edge in enumerate(triangles_edges): edge.nxt = triangles_edges[(edge_idx + 1) % 3] edge.prev = triangles_edges[(edge_idx + 3 - 1) % 3] edge.incident_face = triangle_face triangle_vertices[edge_idx].incident_edge = edge
def detect(self, images): faces = [] for ind, img in enumerate(images): print("Detecting faces in image {}/{}".format( ind + 1, len(images))) newfaces = [] fls = fr.face_locations(img.getImage(), model=self.model_name) encs = fr.face_encodings(img.getImage(), fls) for (fl, enc) in zip(fls, encs): face = Face() face.bound_box = fl face.img_name = img.fileName face.enc = enc tlx, tly, brx, bry = fl x1 = tlx x2 = brx y1 = bry y2 = tly face.myFace = img.image[x1:x2, y1:y2] newfaces.append(face) img.faces = np.array(newfaces) faces += newfaces return faces