def extract(self, img, face_records):
    if isinstance(img, np.ndarray):
        im = self._converttoRocImage(img)
    for face_record in face_records.face_records:
        template_dst = roc.roc_template()
        self._rocUnFlatten(face_record.template.buffer, template_dst)
        roc.roc_represent(im, self.algorithm_id_extract, self.recommendedMinFaceSize(), 1, self.recommendedDetectionThreshold(), self.recommendedImgQuality(), template_dst)
        if ((template_dst.algorithm_id & roc.ROC_INVALID) or (template_dst.algorithm_id == 0)):
            continue
        else:
            (xc, yc, w, h) = (template_dst.detection.x, template_dst.detection.y, template_dst.detection.width, template_dst.detection.height)
            x = int((xc - (w * 0.5)))
            y = int((yc - (w * 0.5)))
            assert (face_record.detection.location.x == x), 'They have to be equal cause'
            assert (face_record.detection.location.y == y), 'They have to be equal cause'
            assert (face_record.detection.location.width == w), 'They have to be equal cause'
            assert (face_record.detection.location.height == h), 'They have to be equal cause'
            '\n                default metadata fields : ChinX,ChinY, IOD (inter-occular distance), LeftEyeX, LeftEyeY, NoseRootX,\n                NoseRootY, Path, Pose, Quality, RightEyeX, RightEyeY, Roll\n                '
            metadata_info = json.loads(template_dst.md.decode('utf-8'))
            landmark = face_record.landmarks.add()
            landmark.landmark_id = 'Nose'
            landmark.location.x = metadata_info['NoseRootX']
            landmark.location.y = metadata_info['NoseRootY']
            landmark = face_record.landmarks.add()
            landmark.landmark_id = 'LeftEye'
            landmark.location.x = metadata_info['LeftEyeX']
            landmark.location.y = metadata_info['LeftEyeY']
            landmark = face_record.landmarks.add()
            landmark.landmark_id = 'RightEye'
            landmark.location.x = metadata_info['RightEyeX']
            landmark.location.y = metadata_info['RightEyeY']
            landmark = face_record.landmarks.add()
            landmark.landmark_id = 'ChinX'
            landmark.location.x = metadata_info['ChinX']
            landmark.location.y = metadata_info['ChinY']
            demographic = face_record.attributes.add()
            demographic.key = 'Age'
            demographic.text = str(metadata_info['Age'])
            demographic = face_record.attributes.add()
            demographic.key = 'Gender'
            demographic.text = metadata_info['Gender']
            demographic = face_record.attributes.add()
            demographic.key = 'GeographicOrigin'
            demographic.text = metadata_info['GeographicOrigin']
            demographic = face_record.attributes.add()
            demographic.key = 'Emotion'
            demographic.text = metadata_info['Emotion']
            demographic = face_record.attributes.add()
            demographic.key = 'Artwork'
            demographic.text = metadata_info['Artwork']
            demographic = face_record.attributes.add()
            demographic.key = 'Yaw'
            demographic.text = str(metadata_info['Yaw'])
            face_record.template.buffer = self._rocFlatten(template_dst)
        roc.roc_ensure(roc.roc_free_template(template_dst))
def extract(self, img, face_records):
    if isinstance(img, np.ndarray):
        im = self._converttoRocImage(img)
    for face_record in face_records.face_records:
        template_dst = roc.roc_template()
        self._rocUnFlatten(face_record.template.buffer, template_dst)
        roc.roc_represent(im, self.algorithm_id_extract, self.recommendedMinFaceSize(), 1, self.recommendedDetectionThreshold(), self.recommendedImgQuality(), template_dst)
        if ((template_dst.algorithm_id & roc.ROC_INVALID) or (template_dst.algorithm_id == 0)):
            continue
        else:
            (xc, yc, w, h) = (template_dst.detection.x, template_dst.detection.y, template_dst.detection.width, template_dst.detection.height)
            x = int((xc - (w * 0.5)))
            y = int((yc - (w * 0.5)))
            assert (face_record.detection.location.x == x), 'They have to be equal cause'
            assert (face_record.detection.location.y == y), 'They have to be equal cause'
            assert (face_record.detection.location.width == w), 'They have to be equal cause'
            assert (face_record.detection.location.height == h), 'They have to be equal cause'
            '\n                default metadata fields : ChinX,ChinY, IOD (inter-occular distance), LeftEyeX, LeftEyeY, NoseRootX,\n                NoseRootY, Path, Pose, Quality, RightEyeX, RightEyeY, Roll\n                '
            metadata_info = json.loads(template_dst.md.decode('utf-8'))
            landmark = face_record.landmarks.add()
            landmark.landmark_id = 'Nose'
            landmark.location.x = metadata_info['NoseRootX']
            landmark.location.y = metadata_info['NoseRootY']
            landmark = face_record.landmarks.add()
            landmark.landmark_id = 'LeftEye'
            landmark.location.x = metadata_info['LeftEyeX']
            landmark.location.y = metadata_info['LeftEyeY']
            landmark = face_record.landmarks.add()
            landmark.landmark_id = 'RightEye'
            landmark.location.x = metadata_info['RightEyeX']
            landmark.location.y = metadata_info['RightEyeY']
            landmark = face_record.landmarks.add()
            landmark.landmark_id = 'ChinX'
            landmark.location.x = metadata_info['ChinX']
            landmark.location.y = metadata_info['ChinY']
            demographic = face_record.attributes.add()
            demographic.key = 'Age'
            demographic.text = str(metadata_info['Age'])
            demographic = face_record.attributes.add()
            demographic.key = 'Gender'
            demographic.text = metadata_info['Gender']
            demographic = face_record.attributes.add()
            demographic.key = 'GeographicOrigin'
            demographic.text = metadata_info['GeographicOrigin']
            demographic = face_record.attributes.add()
            demographic.key = 'Emotion'
            demographic.text = metadata_info['Emotion']
            demographic = face_record.attributes.add()
            demographic.key = 'Artwork'
            demographic.text = metadata_info['Artwork']
            demographic = face_record.attributes.add()
            demographic.key = 'Yaw'
            demographic.text = str(metadata_info['Yaw'])
            face_record.template.buffer = self._rocFlatten(template_dst)
        roc.roc_ensure(roc.roc_free_template(template_dst))