def __init__(self, deckName, cardDict): self.deckName = deckName self.faces = [] self.faces.append(Face(cardDict, 0)) if 'card_faces' in cardDict.keys(): self.faces.append(Face(cardDict, 1))
def ParseInp(fname, bIsolate): ######## Parse input file with open(args.inp_filename) as fid: lines = fid.readlines() for i, line in enumerate(lines): if line.startswith("*Node"): inodes = i + 1 if line.startswith("*Element"): iel = i + 1 break nlines = len(lines) nvertex = iel - inodes - 1 vertex = np.zeros((nvertex, 3), dtype=object) vid = np.zeros((nvertex), dtype=int) # Fill in vertex array vid_lookup = {} for i0, i in enumerate(range(inodes, iel - 1)): vals = lines[i].split(",") vid_lookup[int(vals[0])] = i0 vertex[i0, :] = [float(val) for val in vals[1:4]] # Fill in the triangles array faces = [] triangles = [] for i in range(iel, nlines): line = lines[i] if line.startswith("*Element"): if bIsolate: myFace = Face(vertex=None, connect=np.asarray(triangles)) faces.append(myFace) triangles = [] continue val = [int(v) for v in lines[i].split(",")[1:4]] triangles.append(val) myFace = Face(vertex=None, connect=np.asarray(triangles)) faces.append(myFace) for myFace in faces: myFace.reindex(vid_lookup) # reorder vertex from 0 to n where n is the number of vertice in the face unique_vid = list(set(list(myFace.connect.flatten()))) vid_lu = {unique_vid[k]: k for k in range(len(unique_vid))} myFace.reindex(vid_lu) vertex0 = vertex[unique_vid, :] myFace.vertex = vertex0 return faces
def init_faces(self) -> None: for i, edge1 in enumerate(self.edges): for j, edge2 in enumerate(self.edges_vertices_dict[edge1.vertex2]): if edge1 == edge2: continue flag = False for face in self.faces: if edge1 in face and edge2 in face: flag = True break if flag: continue self.faces.append(Face([edge1, edge2])) act_face = self.faces[-1] act_edge = edge2 while not act_edge.vertex2 == edge1.vertex1: for edge3 in self.edges_vertices_dict[act_edge.vertex2]: if edge3 != act_edge and edge3 in act_face: act_face.edges.append(edge3) act_edge = edge3 break else: self.faces.pop() break
def stack(self): emptyFace = Face(' ') row1 = np.hstack((emptyFace.state, self.top.state, emptyFace.state)) row2 = np.hstack((self.left.state, self.front.state, self.right.state)) row3 = np.hstack((emptyFace.state, self.down.state, emptyFace.state)) row4 = np.hstack((emptyFace.state, self.back.state, emptyFace.state)) joinedCube = np.vstack((row1, row2, row3, row4)) return joinedCube
def faces(self): """ Return an array of current faces on the frame taking into account the 'confThreshold' (empty if not process or if no face has been detected with this conf_threshold) """ res = [] if(self.isFacesLoaded() == False): return res for face in self.getCurrentCacheData()['faces']: face = Face().setJSONData(face) if(face.confidence > self.faceDetector.confThreshold): res.append(face) return res
def detectAllFaces(frame, faces, encodings): #scan the entire frame for detect new faces. newFaces = [] for location in face_recognition.face_locations(frame): newFace = Face(location, '') name = lookForFace(location, faces) if len(name) > 0: newFace.name = name else: newFace.name = getName(frame, location, encodings) newFaces.append(newFace) faces[:] = newFaces[:]
def __init__(self, id=0, name="", relationship="", data="", encoding="", faceId=0): self.id = id self.name = name self.face = Face(faceId, data, encoding) self.getRelation(relationship)
def __init__(self): self.front_face = Face(Color.red) self.back_face = Face(Color.orange) self.left_face = Face(Color.green) self.right_face = Face(Color.blue) self.top_face = Face(Color.white) self.bottom_face = Face(Color.yellow)
def image_callback(self, data): self.faceCascade = cv2.CascadeClassifier("Faces.xml") #print("NEW IMAGE") global METERS_PER_FEET global message try: frame = np.asarray(self.bridge.imgmsg_to_cv2(data, "bgr8")) #build a color image and check for AR markers in it except CvBridgeError as e: print(e) #Set min area to be recognized as a face minH = frame.shape[0] * 0.1 minW = frame.shape[1] * 0.1 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = self.faceCascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5, minSize=(int(minW), int(minH))) for (x, y, w, h) in faces: #print("Saw a Face") cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) self.id, confidence = self.recognizer.predict(gray[y:y + h, x:x + w]) # Check if confidence is less them 125 ==> "0" is perfect match if (confidence < 125): #Detected known face self.id = self.names[self.id] confidence = " {0}%".format(round(100 - confidence)) else: #Flag face as unknown self.id = "unknown" confidence = " {0}%".format(round(100 - confidence)) face = Face(x, y, w, h, -1, str(self.id)) face.z = self.depth_image[int(face.ymid)][int( face.xmid)] * METERS_PER_FEET #Converts meters to feet if math.isnan(face.z): # Check if face is too close face.z = -1 #Publish Message message.x = face.x message.y = face.y message.z = face.z message.h = face.h message.w = face.w message.name = face.name self.pub.publish(message)
def search(self): faceTest = Face() JPG = "Capture.png" path = faceTest.search(JPG) # If this customer has been existed in the faces directory if path != None: #Show the picture of current customer self.getCustomerInfor(path) # If not,load into the directory else: extensive_name = JPG[len(JPG) - 4:len(JPG)] self.loadEvent(extensive_name) print("Loaded successfully!")
def cozmo_program(robot: cozmo.robot.Robot): f = Face(robot) f.find_person() d = Drive(robot) weather = Weather(f.city) weather.set_outfit() welcome = Welcome(robot) welcome.hello(weather.w, weather.outfit, f.city, f.name) e = input() if e == "exit": robot.say_text("Goodbye") else: l = Lights() l.set_lights(d, weather.number) d.find(weather.number)
def recognize_face(): global current_card_id global name global data start = time.time() encoded_img = request.form.get('encodedImg') print(name) a = Face() result = a.from_backend(current_card_id, encoded_img[22:], name) data = result with open("./Result/{}.jpg".format(current_card_id), "rb") as image_file: image = b'data:image/jpeg;base64,' + base64.b64encode(image_file.read()) end = time.time() print(end-start) return image
def detect_face(self, frame): """ return the Face Object with the max size :param frame: camera frame, np.array :return: Face Object """ self.__face_list.clear() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = self.__face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5) if len(faces) > 0: for face in faces: self.__face_list.append(Face(face)) sorted(self.__face_list, key=lambda x: x.calculate_size(), reverse=True) return self.__face_list[0] return None
def calc_optic_flow(self, prev_frame, prev_faces): #new_faces = [] #cv2.imshow("ff",prev_frame) #for face in prev_faces: points = self.get_points(prev_faces[0]) new_face = (optic_flow(prev_frame, self.frame, points)) #for face in new_faces: face_object = Face(new_face, self.frame, prev_faces, (255, 0, 0)) # check if face exists and choose the face with most organs if face_object.organs_counter > 0: face1, i = self.search_face(face_object) if face1 == None: self.faces.append(face_object) elif face_object.organs_counter > face1.organs_counter: self.faces[i] = face_object
def add_face(self, id = 0, name = "test face"): """ Adds face (network interfaces) to the node. face - object of the Face class :param id: id of the face :param name: name of the face :return: true if face is added to the node and false if it not. """ face = Face(id, name,'127.0.0.1', self) try: if not isinstance(face, Face): raise TypeError("face object is incorrect") else: self.__faces.append(face) return True except TypeError: print("incorrect face object") return False
def get_faces(image, threshold=0.5, minsize=20): # img = img_to_np(image) # face detection parameters threshold = [0.6, 0.7, 0.7] # three steps's threshold factor = 0.709 # scale factor faces = [] bounding_boxes, points = detect_face(image, minsize, pnet, rnet, onet, threshold, factor) idx = 0 for bb in bounding_boxes: # print(bb[:4]) # img = image.crop(bb[:4]) # bb[2:4] -= bb[:2] # faces.append(Face(*bb, img)) landmark = points[:, idx].reshape((2, 5)).T bbox = bb[0:4] euler = calculate_euler(image, landmark) # print(landmark) # test_img = image[...,::-1] # for i in range(np.shape(landmark)[0]): # x = int(landmark[i][0]) # y = int(landmark[i][1]) # cv2.circle(test_img, (x, y), 2, (255, 0, 0)) # # img_size = np.asarray(image.shape)[0:2] # bb[0] = np.maximum(bb[0] - face_crop_margin / 2, 0) # bb[1] = np.maximum(bb[1] - face_crop_margin / 2, 0) # bb[2] = np.minimum(bb[2] + face_crop_margin / 2, img_size[1]) # bb[3] = np.minimum(bb[3] + face_crop_margin / 2, img_size[0]) # cropped = image[int(bb[1]):int(bb[3]), int(bb[0]):int(bb[2]), :] # img = misc.imresize(cropped, (face_crop_size, face_crop_size), interp='bilinear') img = alignment(image, bbox, landmark, (112, 112)) if face_crop_size != 112: img = misc.imresize(img, (face_crop_size, face_crop_size), interp='bilinear') faces.append(Face(bb[0], bb[1], bb[2], bb[3], bb[4], img.copy(), euler)) idx = idx + 1 # plt.imshow(test_img) # plt.show() return faces
def textFace2(): urborg = { "tcgplayer_id": 234275, "cardmarket_id": 548301, "name": "Urborg, Tomb of Yawgmoth", "layout": "normal", "mana_cost": "", "cmc": 0.0, "type_line": "Legendary Land", "oracle_text": "Each land is a Swamp in addition to its other land types.", "colors": [], "color_identity": [], "keywords": [], "frame_effects": ["legendary"] } testFace = Face(urborg, 0) print(testFace.__dict__)
def start_cam(self): while (True): _, frame = self.cap.read() gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = self.face_classifier.detectMultiScale(gray_frame, 1.3, 5) for x, y, w, h in faces: new_face = Face(x, y, w, h, frame) avg_b, avg_g, avg_r = new_face.get_avg_color_from_forehead() low_skin_color = (avg_b - self.range_factor, avg_g - self.range_factor, avg_r - self.range_factor) high_skin_color = (avg_b + self.range_factor, avg_g + self.range_factor, avg_r + self.range_factor) nose_to_chin = new_face.get_mouth_area() threshsv = cv2.inRange(nose_to_chin, low_skin_color, high_skin_color) threshsv = cv2.erode(threshsv, self.kernel, iterations=1) thresh_flat = threshsv.flatten() amount_of_white = sum(thresh_flat == 255) ratio_between_pixels_to_white = threshsv.size / amount_of_white if ratio_between_pixels_to_white > self.min_ratio_between_white_pixels_to_image_size: cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) #green ractangle if mask is on properly else: cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2) #red rectangle if mask is not on properly cv2.imshow("thresholded image", threshsv) cv2.imshow('Frame', frame) if cv2.waitKey(20) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
def face_detection(self, prev_faces): # find faces ####################### face_cascade = cv2.CascadeClassifier( os.getcwd() + '\\haarcascades\\haarcascade_frontalface_default.xml') faces = face_cascade.detectMultiScale(self.frame, 1.5, 2) p_faces = face_cascade.detectMultiScale(self.frame, 1.85, 2) if len(faces) == 0: faces = p_faces elif len(p_faces) != 0: faces = np.concatenate((faces, p_faces), 0) # choose the face with most face-organs for i, face in enumerate(faces): x, y, w, h = face.ravel() face_object = Face(face, self.frame, prev_faces, (255, 0, 0)) if face_object.organs_counter > 0: if not self.is_face_exists(face): self.faces.append(face_object) else: face1, j = self.search_face(face_object) if face_object.organs_counter > face1.organs_counter: self.faces[j] = face_object
def face_detection(self, prev_faces): # find faces print(d.items()) face_cascade = cv2.CascadeClassifier( 'C:\Users\Katia\Anaconda3\pkgs\opencv-3.1.0-np111py35_1\Library\etc\haarcascades\haarcascade_frontalface_default.xml' ) faces = face_cascade.detectMultiScale(self.frame, 1.5, 2) p_faces = face_cascade.detectMultiScale(self.frame, 1.85, 2) if len(faces) == 0: faces = p_faces elif len(p_faces) != 0: faces = np.concatenate((faces, p_faces), 0) # choose the face with most face-organs for i, face in enumerate(faces): x, y, w, h = face.ravel() face_object = Face(face, self.frame, prev_faces, (255, 0, 0)) if face_object.organs_counter > 0: if not self.is_face_exists(face): self.faces.append(face_object) else: face1, j = self.search_face(face_object) if face_object.organs_counter > face1.organs_counter: self.faces[j] = face_object
# Draw a label with a name below the face cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (blue, green, red), cv2.FILLED) font = cv2.FONT_HERSHEY_DUPLEX cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1) # Display the resulting image cv2.imshow('Video', frame) #Carrega a camera video_capture = cv2.VideoCapture(0) #Cria os objetos jonas = Face(face_recognition.load_image_file("image.jpg"), 0, 255, 0, 'Jonas') lucas = Face(face_recognition.load_image_file("image1.jpg"), 0, 255, 0, 'Lucas') juan = Face(face_recognition.load_image_file("image2.jpg"), 0, 255, 0, 'Juan') faces = [juan, lucas, jonas] #x = len(faces) -> retorna o tamanho do array encoded_images = [] face_locations = [] face_encodings = [] process_this_frame = True for face in faces: image_face_encoding = face_recognition.face_encodings(face.getFoto())[0] encoded_images.append(image_face_encoding)
# Input input = [[20, 80], [40, 60], [20, 30], [70, 70], [60, 50]] # Make the event queue queue = PriorityQueue() beachline = BeachLine() dcel = DoublyConnectedEdgeList(0, 0, 100, 100) for i in range(0, len(input) // 2): # Create a new site for this point siteEvent = SiteEvent(input[i][0], input[i][1]) queue.Push(siteEvent) # Instantiate and add the face object in the dcel here siteEvent.face = Face(siteEvent) dcel.faceList.append(siteEvent.face) while not queue.IsEmpty(): thisEvent = queue.Pop() if thisEvent is not None: thisEvent.Handle(queue, beachline, dcel) else: break # Complete incomplete faces that may have dangling edges that need to get clipped by the bounds for face in dcel.faceList: face.CompleteFaceIfIncomplete(dcel) print("Finished computing Voronoi Diagram")
def initCube(self): return Face('Y'), Face('O'), Face('B'), Face('R'), Face('W'), Face('G')
""" 人脸情绪分类器 """ import argparse import os from Face import Face from emotion_detect import emotion_detect from train_emotion_classifier import train_emotion_classifier from train_gender_classifier import train_gender_classifier from video_emotion_detect import video_emotion_detect from utils.preprocessor import generate_images_list face = Face() function_table = { 'detect': face.detect, # 人脸检测 'cnn_detect': face.cnn_detect, # 基于CNN的人脸检测 'landmark_detect': face.landmark_detect, # 人脸特征点检测 'recognition': face.recognition, # 人脸识别 'alignment': face.alignment, # 人脸对齐 'clustering': face.clustering, # 人脸聚类 'jitter': face.jitter, # 人脸抖动/增强 'emotion_detect': emotion_detect, # 人脸情绪检测 'emotion_classifier': train_emotion_classifier, # 训练情绪分类器 'gender_classifier': train_gender_classifier, # 训练性别分类器 'video_emotion_detect': video_emotion_detect, # 视频实时情绪检测 } def main(): parser = argparse.ArgumentParser("人脸情绪识别分类器") parser.add_argument("--file", type=str, help="指定需要探测人脸图片文件名") parser.add_argument("--folder", type=str, help="指定需要探测人脸图片的文件夹") parser.add_argument("--method", type=str, default=None, help="指定所使用的方法:[METHOD: detect, cnn_detect, emotion_detect, recognition, alignment, clustering, jitter]")
def __init__(self, n): self.relation_representation = { "F": [[17, 19, 22, 24], [9, 3, 46, 32], [1, 27, 14, 48], [35, 33, 40, 38], [6, 25, 16, 43], [11, 8, 41, 30], [18, 21, 23, 20], [7, 28, 42, 13]], "B": [[33, 35, 40, 38], [34, 37, 39, 36], [3, 9, 46, 32], [2, 12, 47, 29], [1, 14, 48, 27]], "L": [[9, 11, 16, 14], [10, 13, 15, 12], [1, 17, 41, 40], [4, 20, 44, 37], [6, 22, 46, 35]], "U": [[1, 3, 6, 8], [14, 38, 22, 30], [40, 32, 16, 24], [46, 48, 41, 43], [35, 27, 11, 19], [9, 33, 17, 25], [2, 5, 7, 4], [47, 45, 42, 44], [39, 31, 23, 15], [12, 36, 28, 20], [37, 29, 21, 13], [34, 26, 18, 10]], "D": [[41, 43, 46, 48], [16, 24, 40, 32], [22, 30, 14, 38], [42, 44, 45, 47], [23, 15, 31, 39]], "R": [[25, 27, 32, 30], [26, 29, 31, 28], [3, 38, 43, 19], [5, 36, 45, 21], [8, 33, 48, 24]] } self.ideal_cube = { 'U': Face(n, "U", 1), 'L': Face(n, "L", 9), 'F': Face(n, "F", 17), 'R': Face(n, "R", 25), 'B': Face(n, "B", 33), 'D': Face(n, "D", 41) } self.cube = { 'U': Face(n, "U", 1), 'L': Face(n, "L", 9), 'F': Face(n, "F", 17), 'R': Face(n, "R", 25), 'B': Face(n, "B", 33), 'D': Face(n, "D", 41) } self.n = n self.sides_relations = { "U": [["B", 0], ["R", 0, -1], ["F", 0, -1], ["L", 0, -1]], "L": [["F", 2], ["D", 2, -1], ["B", 3, 1], ["U", 2, -1]], "F": [["U", 1], ["R", 2, -1], ["D", 0, -1], ["L", 3, 1]], "R": [["U", 3], ["B", 2, -1], ["D", 3, 1], ["F", 3, 1]], "B": [["U", 0], ["L", 2, -1], ["D", 1, 1], ["R", 3, 1]], "D": [["F", 1], ["R", 1, 1], ["B", 1, 1], ["L", 1, 1]] } self.commands = [ "L", "l", "R", "r", "F", "f", "B", "b", "U", "u", "D", "d" ] self.sides = ["L", "F", "R", "B"]
def newFace(self, _edge): self.numOfFaces += 1 self.faces.append(Face(self.vertexes, self.faces, self.hedges, _edge)) self.faces[-1].index = self.numOfFaces - 1 return len(self.faces) - 1
nargs=1, metavar=("N"), type=int, required=True, help="number of initial refine steps", ) parser.add_argument( "--P", nargs=1, metavar=("P"), type=int, required=True, help="number of and refine/smoothing steps", ) args = parser.parse_args() fid = open(args.input_file) myFace = Face.from_ts(fid) a = trimesh.Trimesh(vertices=myFace.vertex, faces=myFace.connect) for i in range(args.N[0]): a = a.subdivide() for i in range(args.P[0]): a = a.subdivide() a = trimesh.smoothing.filter_taubin(a) myFace = Face(a.vertices, a.faces) basename, ext = os.path.splitext(args.input_file) myFace.write(f"{basename}_refined_smooth_{args.N[0]}{ext}")
from flask import Flask, render_template, Response, request, flash from Camera import Camera from Database import Database from Face import Face from Uploader import Uploader app = Flask(__name__) app.secret_key = "aaaaaaa" UPLOAD_FOLDER = "." app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER db = Database() face = Face(db) cam = Camera(0, face) uploader = Uploader(app, UPLOAD_FOLDER) @app.route("/") def index(): return render_template("index.html") @app.route("/video_feed") def video_feed(): return Response(cam.stream(scale=0.3), mimetype="multipart/x-mixed-replace; boundary=frame") @app.route("/register", methods=["GET", "POST"]) def register():
structured_grid.smooth(args.smooth[0]) structured_grid.generate_vertex() structured_grid.generate_connect() structured_grid.isolate_hole(args.hole) if args.proj: structured_grid.proj_vertex(args.proj[0]) if args.translate: structured_grid.translate(args.translate) basename, ext = os.path.splitext(args.output_file) nsolid = max(structured_grid.solid_id) + 1 if nsolid == 1: myFace = Face(structured_grid.vertex, structured_grid.connect) if structured_grid.is_sparse: myFace.reindex(structured_grid.vid_lookup) myFace.write(f"{basename}{ext}") else: for sid in range(nsolid): idtr = np.where(structured_grid.solid_id == sid)[0] aVid = np.unique(structured_grid.connect[idtr, :].flatten()) myFace = Face(vertex=None, connect=structured_grid.connect[idtr, :]) if structured_grid.is_sparse: myFace.reindex(structured_grid.vid_lookup) myFace.write(f"{basename}{sid}{ext}", structured_grid.vertex, write_full_vertex_array=False)
import cv2 from Face import Face from Message import Message from time import sleep cap = cv2.VideoCapture(0) text_position = (10, 30) font = cv2.FONT_HERSHEY_SIMPLEX scale = 1 colour = (255, 255, 255) face = Face("faces") message = Message() while (True): ret, frame = cap.read() name = face.get_name(frame, source_type="video") if name: cv2.putText(frame, name, text_position, font, scale, colour) message.update(name) cv2.imshow('frame', frame) if cv2.waitKey(20) & 0xFF == ord('q'): break sleep(1) cap.release()