Example #1
0
    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))
Example #2
0
def test(fibMethod1,fibMethod2):
    apiFace = Face(appStats,'/test/'+fibMethod1+'/'+fibMethod2,request.method,'Compare library '+fibMethod2+' to '+fibMethod1)
    appTests = FuncTest()
    lib1 = appTests.getStandardDictionary()
    lib2 = appTests.getTestDictionary()
    appTests.runLibraryTests(fibMethod1,lib1)
    appTests.runLibraryTests(fibMethod2,lib2)
    testResults = appTests.compare()
    if appTests.testsPassed() == True: overall = "Pass"
    else: overall = "Fail"
    return apiFace.response(appStats,overall,apiFace.dictionaryToJson(sorted(testResults.iteritems())))
Example #3
0
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)
Example #5
0
    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)
Example #6
0
def fibFloor(fibMethod,fibItem):
    apiFace = Face(appStats,'/floor/'+fibMethod,request.method,'Generate a Fibonacci sequence with max value less than '+fibItem+' using method '+fibMethod)
    if int(fibItem) < 0:
      return apiFace.response(appStats,'Fail',"API does not support negative target values")
    try:
      methodLoad = __import__(fibMethod)
      dynLoad = 'methodLoad.'+fibMethod+'()'
      fib = eval(dynLoad)
      list1 =  fib.fibFloor(int(fibItem))
    except:
      return apiFace.response(appStats,'Fail',fibMethod+' returned an error')
    else:
      return apiFace.response(appStats,'Pass',apiFace.listToJson(list1))
Example #7
0
def fibValue(fibMethod,fibItem):
    apiFace = Face(appStats,'/value/'+fibMethod,request.method,'Generate a Fibonacci number at sequence '+fibItem+' using method '+fibMethod)
    if int(fibItem) < 0:
      return apiFace.response(appStats,'Fail',"API does not support negative sequence values")
    try:
      methodLoad = __import__(fibMethod)
      dynLoad = 'methodLoad.'+fibMethod+'()'
      fib = eval(dynLoad)
      fibValue =  fib.fibAtN(int(fibItem))
    except:
      return apiFace.response(appStats,'Fail',fibMethod+' returned an error')
    else:
      return apiFace.response(appStats,'Pass',str(fibValue))
Example #8
0
def fibSequence(fibMethod,fibLen):
    apiFace = Face(appStats,'/sequence/'+fibMethod,request.method,'Generate a Fibonacci sequence with '+fibLen+' elements using method '+fibMethod)
    if int(fibLen) < 0:
      return apiFace.response(appStats,'Fail',"API does not allow negative length")
    try:
      methodLoad = __import__(fibMethod)
      dynLoad = 'methodLoad.'+fibMethod+'()'
      fib = eval(dynLoad)
      list1 =  fib.fibList(int(fibLen))
    except:
      return apiFace.response(appStats,'Fail',fibMethod+' returned an error')
    else:
      return apiFace.response(appStats,'Pass',apiFace.listToJson(list1))
Example #9
0
    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)
Example #11
0
    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
Example #12
0
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
class Friend:
    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 toDict(self):
        friendDict = {
            'id': self.id,
            'name': self.name,
            'relationship': self.relationship.name,
            'face': self.face.toDict()
        }

        return friendDict

    def getRelation(self, relationship):
        if relationship.lower() == "friend":
            self.relationship = Relationship.Friend
        elif relationship.lower() == "family":
            self.relationship = Relationship.Family
        elif relationship.lower() == "colleague":
            self.relationship = Relationship.Colleague
        elif relationship.lower() == "self":
            self.relationship = Relationship.Self
        else:
            self.relationship = Relationship.NoRelation
Example #14
0
 def check_face(self, face: Face):
     sides = list()
     for vertex in self.vertices:
         if vertex not in face:
             sides.append(face.side(vertex))
     return all(
         map(lambda i: sides[i] == sides[i + 1], range(len(sides) - 1)))
Example #15
0
 def add_face(self, points_arr):
     '''
     Method add face to faces collection. It get a sequence 
     of numbers which means position in point collection.       
     '''
     try:
         if len(points_arr) < 4:
             raise ParserException('Face contains more that 4 point')
         face = Face(self.vertices[int(points_arr[0])],self.vertices[int(points_arr[1])],self.vertices[int(points_arr[2])],self.vertices[int(points_arr[3])])
         face.order = [int(points_arr[0]),int(points_arr[1]),int(points_arr[2]),int(points_arr[3])]
         self.faces[face.order] = face
         #self.faces.append(face)
     except ParserException as ex:
         print 'Error:%s'%ex
         print points_arr
         raise ex 
Example #16
0
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
Example #17
0
 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
Example #18
0
 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 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()
Example #20
0
def placeImageWithMashape(origPilImage,origImageUrl,imageHat, personIndex):
##################MASHAPE
    client = Face("1vgorh7zmjvdnjq2xjwqq6xnwm6xa4", "zhyjc7xytpu3rcwjy3akzzqiirb3ev")
    faceData = client.detect(images='http://www.taipeitimes.com/images/2012/11/08/thumbs/P03-121108-1.jpg')
    numberOfObjects = len(faceData.body['photos'][0]['tags'])
    if (personIndex is not None) and (0 <= personIndex < numberOfObjects):
        faceIndex = personIndex
    else:
        faceIndex = randrange(numberOfObjects)

    singleFaceData = faceData.body['photos'][0]['tags'][faceIndex]
    faceWidth = singleFaceData['width']
    faceHeight = singleFaceData['height']
    faceXcord = singleFaceData['center']['x'] 
    faceYcord = singleFaceData['center']['y']
    hatWidth = int(math.floor(faceWidth * 2))
    ratio = float(hatWidth) /float(imageHat.size[0])
    hatHeight = int(math.floor(imageHat.size[1] *ratio))  
    imageHatResized = imageHat.resize((hatWidth, hatHeight),PilImage.ANTIALIAS)
    faceX = int(math.floor(faceXcord - imageHatResized.size[0]/2.0))
    faceY = int(math.floor(faceYcord - imageHatResized.size[1]/2.0 - faceHeight/2.0*0.3 ))
    faceY = faceY - faceHeight/2 
    origPilImage.paste(imageHatResized, (faceX, faceY), imageHatResized)
    return (origPilImage , faceIndex)
    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
Example #22
0
    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
Example #23
0
 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
Example #24
0
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
Example #25
0
def fibCeiling(fibMethod,fibItem):
    apiFace = Face(appStats,'/ceiling/'+fibMethod,request.method,'Generate a Fibonacci sequence with max value one sequence item higher than '+fibItem+' using method '+fibMethod)
    if int(fibItem) < 0:
      return apiFace.response(appStats,'Pass',apiFace.listToJson([0]))
    try:
      methodLoad = __import__(fibMethod)
      dynLoad = 'methodLoad.'+fibMethod+'()'
      fib = eval(dynLoad)
      list1 =  fib.fibCeil(int(fibItem))
    except:
      return apiFace.response(appStats,'Fail',fibMethod+' returned an error')
    else:
      return apiFace.response(appStats,'Pass',apiFace.listToJson(list1))
Example #26
0
def userMethods():
    if request.method == 'GET':
        response='list user methods'
        apiFace = Face(appStats,'/userMethods/',request.method,'list Fibonacci libraries available')
        return apiFace.response(appStats,'Pass',apiFace.dictionaryToJson(libs.list()))
    elif request.method == 'PUT':
        response='update user method'
        apiFace = Face(appStats,'/userMethods/',request.method,'update Fibonacci libraries available')
    elif request.method == 'POST':
        response='create user method'
        apiFace = Face(appStats,'/userMethods/',request.method,'create Fibonacci libraries available')
        #libs.add('TableFib','limited recursion with simple storage')
    elif request.method == 'DELETE':
        response='drop user method'
        apiFace = Face(appStats,'/userMethods/',request.method,'drop Fibonacci libraries available')

    return apiFace.response(appStats,'Fail','not supported:'+response)
Example #27
0
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 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
    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
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()
Example #31
0
    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"]
Example #32
0
    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}")
Example #33
0
def runtime_error(error=None):
  apiFace = Face(appStats,'500 Error',request.method,'python runtime error encountered, see server output')
  return apiFace.response(appStats,"Error",'500')
Example #34
0
def root():
    apiFace = Face(appStats,'/',request.method,"Welcome to Blair's Fibonacci API")
    return apiFace.response(appStats,None,None)
Example #35
0
def wrong_method(error=None):
  apiFace = Face(appStats,'405 Error',request.method,'request type not allowed')
  return apiFace.response(appStats,"Error",'405')
Example #36
0
def not_found(error=None):
  apiFace = Face(appStats,'404 Error',request.method,'URL not found')
  links = []
  for rule in app.url_map.iter_rules():
    if rule.endpoint != 'static': links.append(rule.endpoint)
  return apiFace.response(appStats,'401 Error',apiFace.listToJson(sorted(links)))
Example #37
0
def forbidden(error=None):
  apiFace = Face(appStats,'401 Error',request.method,'user is not allowed to access the resource')
  return apiFace.response(appStats,"Error",'403')
Example #38
0
# To use the Face API in your code, just import the generated code
# add your developer key (you can find it in your dashboard: http://www.mashape.com/account/index )
# and relax!
# This is a sample of the initialization of the client.. then call its methods!


from Face import Face

# basic instantiation. TODO Put your authentication keys here.
client = Face("1vgorh7zmjvdnjq2xjwqq6xnwm6xa4", "zhyjc7xytpu3rcwjy3akzzqiirb3ev")


api.detect(urls="http://www.lambdal.com/test2.jpg")

# A sample function call. These parameters are not properly filled in.
# See Face.py to find all function names and parameters.
response = client.detect(images='http://www.taipeitimes.com/images/2012/11/08/thumbs/P03-121108-1.jpg')

# now you can do something with the response.
print vars(response)
    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)
Example #40
0
def status():
    apiFace = Face(appStats,'/status/',request.method,"health check")
    print url_for('status')
    #return status and result
    return apiFace.response(appStats,'healthy',apiFace.dictionaryToJson(appStats.getStats()))
Example #41
0
parser.add_argument("ts_file", help="ts filename")
parser.add_argument("output_filename", nargs="?", help="output filname (if not used = basename.stl)")
parser.add_argument("--proj", nargs=1, metavar=("projname"), help="transform vertex array to projected system.\
projname: name of the (projected) Coordinate Reference System (CRS) (e.g. EPSG:32646 for UTM46N)")
parser.add_argument("--tokm", dest="tokm", action="store_true", help="convert coordinates to km")
parser.add_argument("--translate", nargs=2, metavar=("x0", "y0"), default=([0, 0]), help="translates all nodes by (x0,y0)", type=float)
args = parser.parse_args()


idface = 0
if not args.output_filename:
    args.output_filename = args.ts_file[0:-3] + ".stl"
basename, ext = os.path.splitext(os.path.basename(args.output_filename))

with open(args.ts_file) as fid:
    while True:
        myFace = Face.from_ts(fid)
        if not myFace:
            break
        if args.proj:
            myFace.proj(args.proj[0])
        if args.tokm:
            myFace.scale_vertex([0.001, 0.001, 0.001])
        if args.translate:
            myFace.translate_vertex([args.translate[0], args.translate[1], 0])
        if ext in [".stl", ".ts"]:
            myFace.write(f"{basename}{ext}", append=(idface != 0))
        else:
            myFace.write(f"{basename}{idface}{ext}")
        idface += 1
Example #42
0
def apiList():
    apiFace = Face(appStats,'/apiList/',request.method,"List of available API endpoints")
    links = []
    for rule in app.url_map.iter_rules():
      if rule.endpoint != 'static': links.append(rule.endpoint)
    return apiFace.response(appStats,'Pass',apiFace.listToJson(sorted(links)))
Example #43
0
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():
Example #44
0
""" 人脸情绪分类器 """
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]")
Example #45
0
File: Mesh.py Project: Daiver/jff
 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
Example #46
0
def bad_request(error=None):
  apiFace = Face(appStats,'400 Error',request.method,'malformed request')
  return apiFace.response(appStats,"Error",'400')
Example #47
0
        # 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)
Example #48
0
def unauthorized(error=None):
  apiFace = Face(appStats,'401 Error',request.method,'user is not authorized')
  return apiFace.response(appStats,"Error",'401')
Example #49
0
	def obj(fp):
		
		node = Node()
		node.mesh = Mesh()
		with open(fp) as f:
			material = None
			for line in f:
				line = line.strip().split(' ', 1)
				if len(line) == 1: continue
				key, line = line[0], line[1].lstrip()
				if '#' in key: continue
				if 'vn' in key:
					line = line.split(' ')
					node.mesh.addNormal(line[0], line[1], line[2])
				elif 'vt' in key:
					line = line.split(' ')
					node.mesh.addTexCoord(line[0], line[1])
				elif 'usemtl' in key:
					material = None
					for mat in node.materials:
						if line == mat.name:
							material = mat
					if material is None:
						material = Material()
						material.name = line
						node.materials[material] = set()

				elif 'f' in key:
					line = line.split(' ')
					face = Face()
					if material is not None: node.materials[material].add(face)
					# f v//vn 
					if '//' in line[0]:
						line = [int(i) for l in line for i in l.split('//')]
						face.vA = line[0]
						face.vB = line[2]
						face.vC = line[4]
						face.vnA = line[1]
						face.vnB = line[3]
						face.vnC = line[5]
					# f v/vt
					elif line[0].count('/') == 1:
						line = [int(i) for l in line for i in l.split('/')]
						face.vA = line[0]
						face.vB = line[2]
						face.vC = line[4]
						face.vtA = line[1]
						face.vtB = line[3]
						face.vtC = line[5]
					# f v/vt/vn
					elif line[0].count('/') == 2:
						line = [int(i) for l in line for i in l.split('/')]
						face.vA = line[0]
						face.vB = line[3]
						face.vC = line[6]
						face.vtA = line[1]
						face.vtB = line[4]
						face.vtC = line[7]
						face.vnA = line[2]
						face.vnB = line[5]
						face.vnC = line[8]
					# f v
					else:
						face.vA = int(line[0])
						face.vB = int(line[1])
						face.vC = int(line[2])	

					node.mesh.faces.append(face)
				elif 'v' in key:
					line = line.split(' ')
					node.mesh.addVertex(line[0], line[1], line[2])


		if os.path.isfile(fp.replace('.obj', '.mtl')):
			with open(fp.replace('.obj', '.mtl')) as f:
				material = None
				for line in f:
					line = line.strip().split(' ', 1)
					if len(line) == 1: continue
					key, line = line[0], line[1].lstrip()
					if '#' in key: continue
					if 'newmtl' in key:
						for mat in node.materials:
							if mat.name == line: material = mat
					if 'map_Kd' in key:
						material.diffuseMap = line
					elif 'map_Ka' in key:
						material.ambientMap = line
					elif 'Ka' in key:
						line = line.split(' ')
						material.ambient = Color(line[0], line[1], line[2])
					elif 'Kd' in key:
						line = line.split(' ')
						material.diffuse = Color(line[0], line[1], line[2])
		return node