Esempio n. 1
0
 def __init__(self,
         xml_path=cfg.PERSON_DET_XML, 
         device='MYRIAD', 
         inp_size=1, out_size=1, 
         num_requests=2, plugin=None):
     """Initialize Face detector object"""
     self.__net = Network()
     self.plugin, (self.B, self.C, self.H, self.W) = self.__net.load_model(
             xml_path, device, inp_size, out_size, num_requests, plugin=plugin)
Esempio n. 2
0
 def __init__(self,
              xml_path=cfg.HEAD_POSE_XML,
              device='MYRIAD',
              inp_size=1,
              out_size=3,
              num_requests=2,
              plugin=None):
     self.__net = Network()
     self.plugin, (self.B, self.C, self.H,
                   self.W) = self.__net.load_model(xml_path,
                                                   device,
                                                   inp_size,
                                                   out_size,
                                                   num_requests,
                                                   plugin=plugin)
Esempio n. 3
0
class HeadPoser:
    def __init__(self,
                 xml_path=cfg.HEAD_POSE_XML,
                 device='MYRIAD',
                 inp_size=1,
                 out_size=3,
                 num_requests=2,
                 plugin=None):
        self.__net = Network()
        self.plugin, (self.B, self.C, self.H,
                      self.W) = self.__net.load_model(xml_path,
                                                      device,
                                                      inp_size,
                                                      out_size,
                                                      num_requests,
                                                      plugin=plugin)

    def estimatePose(self, face_image):
        image = cv.resize(face_image, (self.W, self.H))
        image = image.transpose((2, 0, 1))
        image = image.reshape((self.B, self.C, self.H, self.W))

        self.__net.exec_net(0, image)
        self.__net.wait(0)

        angle_y = self.__net.get_output(0, 'angle_y_fc')[0, 0]
        angle_p = self.__net.get_output(0, 'angle_p_fc')[0, 0]
        angle_r = self.__net.get_output(0, 'angle_r_fc')[0, 0]

        return angle_y, angle_p, angle_r

    def getPlugin(self):
        return self.plugin
Esempio n. 4
0
class PersonREID:
    def __init__(self,
                 xml_path=cfg.PERSON_REID_XML,
                 device='MYRIAD',
                 inp_size=1,
                 out_size=1,
                 num_requests=2,
                 plugin=None):
        self.__net = Network()
        self.plugin, (self.B, self.C, self.H,
                      self.W) = self.__net.load_model(xml_path,
                                                      device,
                                                      inp_size,
                                                      out_size,
                                                      num_requests,
                                                      plugin=plugin)

    def forward(self, face_image):
        image = cv.resize(face_image, (self.W, self.H))
        #image = image.transpose((2, 0, 1))
        image = image.reshape((self.B, self.C, self.H, self.W))

        self.__net.exec_net(0, image)
        self.__net.wait(0)

        emb = self.__net.get_output(0).reshape(256)

        return emb

    def getPlugin(self):
        return self.plugin
Esempio n. 5
0
class FaceDetector:
    """Face Detector class"""
    def __init__(self,
                 xml_path=cfg.FACE_DET_XML,
                 device='MYRIAD',
                 inp_size=1,
                 out_size=1,
                 num_requests=2,
                 plugin=None):
        """Initialize Face detector object"""
        self.__net = Network()
        self.plugin, (self.B, self.C, self.H,
                      self.W) = self.__net.load_model(xml_path,
                                                      device,
                                                      inp_size,
                                                      out_size,
                                                      num_requests,
                                                      plugin=plugin)

    def getFaces(self, image, def_score=0.5):
        """Detect faces in an input image with given threshold"""
        H, W = image.shape[:2]

        frm = cv.resize(image, (self.W, self.H))
        frm = frm.transpose((2, 0, 1))
        frm = frm.reshape((self.B, self.C, self.H, self.W))

        self.__net.exec_net(0, frm)
        self.__net.wait(0)

        res = self.__net.get_output(0)

        scores, bboxes = [], []
        for obj in res[0][0]:
            if obj[2] > def_score:
                score = obj[2]
                xmin = max(0, int(obj[3] * W))
                ymin = max(0, int(obj[4] * H))
                xmax = min(W, int(obj[5] * W))
                ymax = min(H, int(obj[6] * H))

                scores.append(score)
                bboxes.append([xmin, ymin, xmax, ymax])

        return scores, bboxes

    def getPlugin(self):
        return self.plugin