openface_node.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:openface_ros 作者: schelian 项目源码 文件源码
def _detect_face_srv(self, req):
        try:
            bgr_image = self._bridge.imgmsg_to_cv2(req.image, "bgr8")
        except CvBridgeError as e:
            error_msg = "Could not convert to opencv image: %s" % e
            rospy.logerr(error_msg)
            return {"error_msg": error_msg}

        # Display the resulting frame
        detections = [{"roi": _get_roi(bgr_image, d), "x": d.left(), "y": d.top(),
                       "width": d.width(), "height": d.height()} for d
                      in self._face_detector(bgr_image, 1)]  # 1 = upsample factor

        # Try to recognize
        detections = self._update_detections_with_recognitions(detections)

        rospy.logerr("This is for debugging")
        rospy.logerr(detections)

        # Try to add attributes
        if req.external_api_request:
            detections = self._update_detections_with_attributes(detections)

        # Save images
        if req.save_images:
            self._save_images(detections, bgr_image)

        return {
            "face_detections": [FaceDetection(names=(d["names"] if "name" in d else []),
                                              l2_distances=(d["l2_distances"] if "name" in d else []),
                                              x=d["x"], y=d["y"], width=d["width"], height=d["height"],
                                              gender_is_male=(d["attrs"]["gender"]["value"] == "male" if "attrs" in d else 0),
                                              gender_score=(float(d["attrs"]["gender"]["confidence"]) if "attrs" in d else 0),
                                              age_score=(1.0 if "attrs" in d else 0),
                                              age=(int(d["attrs"]["age_est"]["value"]) if "attrs" in d else 0))
                                for d in detections],
            "error_msg": ""
        }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号