コード例 #1
0
 def _leg_annotation(self,
                     log,
                     activity_rois=list(),
                     nonactivity_rois=list(),
                     wp=""):
     leg_rois = list()
     timestamp = log[0].header.stamp
     for traj in self._trajvis.trajs.traj.itervalues():
         trajectory = traj.get_trajectory_message()
         points = [[pose.pose.position.x, pose.pose.position.y]
                   for pose in trajectory.trajectory]
         points = create_line_string(points)
         for roi, region in self.regions.iteritems():
             if is_intersected(region, points):
                 leg_rois.append(roi)
                 self.roi_leg[roi].append((timestamp.secs / 60) * 60)
     for roi in activity_rois:
         if roi in leg_rois:
             self.leg[roi][wp]["TP"] += 1
         else:
             self.leg[roi][wp]["FN"] += 1
     for roi in nonactivity_rois:
         if roi in leg_rois:
             self.leg[roi][wp]["FP"] += 1
         else:
             self.leg[roi][wp]["TN"] += 1
コード例 #2
0
    def _get_waypoints(self, soma_config):
        region_wps = dict()
        # get regions information
        regions, _ = get_soma_info(soma_config)
        # get waypoint information
        topo_sub = rospy.Subscriber("/topological_map", TopologicalMap,
                                    self._topo_map_cb, None, 10)
        rospy.loginfo("Getting information from /topological_map...")
        while self.topo_map is None:
            rospy.sleep(0.1)
        topo_sub.unregister()

        for wp in self.topo_map.nodes:
            wp_sight, _ = robot_view_cone(wp.pose)
            intersected_rois = list()
            intersected_regions = list()
            for roi, region in regions.iteritems():
                if is_intersected(wp_sight, region):
                    intersected_regions.append(region)
                    intersected_rois.append(roi)
            for ind, region in enumerate(intersected_regions):
                area = wp_sight.intersection(region).area
                roi = intersected_rois[ind]
                if roi in region_wps:
                    _, area1 = region_wps[roi]
                    if area > area1:
                        region_wps.update({roi: (wp.name, area)})
                else:
                    region_wps.update({roi: (wp.name, area)})
        return {
            roi: tupleoftwo[0]
            for roi, tupleoftwo in region_wps.iteritems()
        }
コード例 #3
0
 def _pt_cb(self, msg):
     if self._is_counting_visit:
         for trajectory in msg.trajectories:
             points = [[pose.pose.position.x, pose.pose.position.y]
                       for pose in trajectory.trajectory[-10:]]
             points = create_line_string(points)
             for roi, area in self.regions.iteritems():
                 if is_intersected(area, points):
                     if trajectory.uuid not in self._region_visits:
                         rospy.loginfo("%s seems to visit %s" %
                                       (trajectory.uuid, roi))
                         self._region_visits[trajectory.uuid] = roi
                     break
コード例 #4
0
 def _cd_annotation(self,
                    log,
                    activity_rois=list(),
                    nonactivity_rois=list(),
                    wp=""):
     cd_rois = list()
     timestamp = log[0].header.stamp
     for centroid in self._cd:
         point = create_line_string([centroid.x, centroid.y])
         for roi, region in self.regions.iteritems():
             if is_intersected(region, point):
                 cd_rois.append(roi)
                 self.roi_cd[roi].append((timestamp.secs / 60) * 60)
     for roi in activity_rois:
         if roi in cd_rois:
             self.cd[roi][wp]["TP"] += 1
         else:
             self.cd[roi][wp]["FN"] += 1
     for roi in nonactivity_rois:
         if roi in cd_rois:
             self.cd[roi][wp]["FP"] += 1
         else:
             self.cd[roi][wp]["TN"] += 1
コード例 #5
0
 def _activity_annotation(self, log):
     act_rois = list()
     rospy.logwarn(
         "Please wait until the new image appears before answering...")
     rospy.logwarn("All questions are based on the image topic %s" %
                   rospy.get_name())
     timestamp = log[0].header.stamp
     datestamp = datetime.datetime.fromtimestamp(timestamp.secs)
     wp = list()
     for pose in self._robot_pos:
         point = create_line_string([pose.x, pose.y])
         for wp_name, wp_region in self.topo_map.iteritems():
             if is_intersected(wp_region, point):
                 wp.append(wp_name)
     if wp == list():
         inpt = ""
         while inpt not in self.topo_map.keys():
             text = "Manual, From which region did the robot observed around %s? \n" % str(
                 datestamp)
             text += "Please select from %s:" % str(self.topo_map.keys())
             inpt = raw_input(text)
         wp = inpt
     elif len(list(set(wp))) > 1:
         inpt = ""
         while inpt not in self.topo_map.keys():
             text = "From which region did the robot observed around %s? \n" % str(
                 datestamp)
             text += "Please select from %s:" % str(list(set(wp)))
             inpt = raw_input(text)
         wp = inpt
     else:
         wp = wp[0]
     self.wp_history.update({(timestamp.secs / 60) * 60: wp})
     # listing all regions which activity happened from the image
     text = "Which regions did the activity happen within a minute around %s? \n" % str(
         datestamp)
     text += "Please select from %s, " % str(self.regions.keys())
     text += "and write in the following format '[reg_1,...,reg_n]'\n"
     text += "(Press ENTER if no activity is observed): "
     inpt = raw_input(text)
     inpt = inpt.replace(" ", "")
     inpt = inpt.replace("[", "")
     inpt = inpt.replace("]", "")
     act_rois = inpt.split(",")
     if '' in act_rois and len(act_rois) == 1:
         act_rois = list()
     for roi in act_rois:
         self.activity[roi][wp]["Present"] += 1
         self.roi_activity[roi].append((timestamp.secs / 60) * 60)
     # listing all regions which no activity happening from the image
     text = "Which regions with no activity within a minute around %s? \n" % str(
         datestamp)
     text += "Please select from %s, " % str(self.regions.keys())
     text += "and write in the following format '[reg_1,...,reg_n]'\n"
     text += "(Press ENTER if all regions had an activity): "
     inpt = raw_input(text)
     inpt = inpt.replace(" ", "")
     inpt = inpt.replace("[", "")
     inpt = inpt.replace("]", "")
     nact_rois = inpt.split(",")
     if '' in nact_rois and len(nact_rois) == 1:
         nact_rois = list()
     for roi in nact_rois:
         self.activity[roi][wp]["Absent"] += 1
         self.roi_non_activity[roi].append((timestamp.secs / 60) * 60)
     return act_rois, nact_rois, wp