def predict_now(self):
        query_features = self.query_features
        if not len(query_features.descriptors) > 0:
            return
        descs = np.array(query_features.descriptors)
        X = self.bof.transform([descs])
        normalize(X, copy=False)
        self._pub_debug.publish(Histogram(header=query_features.header, histogram=X[0]))

        object_list = get_object_list()
        proba = self.clf.predict_proba(X)[0]
        matched_idx = np.argmax(proba)
        # prepare message
        res = ObjectRecognition()
        res.header.stamp = query_features.header.stamp
        res.matched = object_list[matched_idx]
        res.probability = proba[matched_idx]
        res.candidates = object_list
        res.probabilities = proba
        return res
 def spin_once(self):
     if self.cfeatures is None:
         rospy.loginfo('color feature is None')
         return
     stamp, objects_proba = self.cfeatures
     target_bin = rospy.get_param('/target', None)
     if target_bin is None:
         rospy.loginfo('target bin is None')
         return
     candidates = self.bin_contents[target_bin]
     proba = [(c, objects_proba[c]) for c in candidates]
     matched = sorted(proba, key=lambda x: x[1])[-1][0]
     # compose msg
     msg = ObjectRecognition()
     msg.header.stamp = stamp
     msg.matched = matched
     msg.probability = objects_proba[matched]
     msg.candidates = candidates
     msg.probabilities = np.array([objects_proba[c] for c in candidates])
     msg.probabilities /= msg.probabilities.sum()
     self.pub.publish(msg)
Beispiel #3
0
    def predict_now(self):
        query_image = self.query_image

        object_list = get_object_list()
        probs = self.match(object_list)
        matched_idx = np.argmax(probs)
        # prepare message
        res = ObjectRecognition()
        res.header.stamp = query_image.header.stamp
        res.matched = object_list[matched_idx]
        res.probability = probs[matched_idx]
        res.candidates = object_list
        res.probabilities = probs
        return res
Beispiel #4
0
    def predict_now(self):
        query_features = self.query_features
        if not len(query_features.descriptors) > 0:
            return
        descs = np.array(query_features.descriptors)
        X = self.bof.transform([descs])
        normalize(X, copy=False)
        self._pub_debug.publish(
            Histogram(header=query_features.header, histogram=X[0]))

        object_list = get_object_list()
        proba = self.clf.predict_proba(X)[0]
        matched_idx = np.argmax(proba)
        # prepare message
        res = ObjectRecognition()
        res.header.stamp = query_features.header.stamp
        res.matched = object_list[matched_idx]
        res.probability = proba[matched_idx]
        res.candidates = object_list
        res.probabilities = proba
        return res
Beispiel #5
0
    def spin_once(self):
        if self.bof_data is None or self.cfeature is None:
            return
        stamp, bof_objects_proba = self.bof_data
        stamp, cfeature_objects_proba = self.cfeature
        weight = self.weight

        target_bin = rospy.get_param('target', None)

        object_list = get_object_list()
        all_proba = [
            (o,
             (weight[o]['bof'] * bof_objects_proba[o]) +
             (weight[o]['color'] * cfeature_objects_proba[o])
             ) for o in object_list
            ]

        # verification result for debug
        candidates = self.bin_contents.get(target_bin, None)
        if candidates is None:
            candidates = object_list
        matched = sorted(all_proba, key=lambda x: x[1])[-1][0]
        # compose msg
        msg = ObjectRecognition()
        msg.header.stamp = stamp
        msg.matched = matched
        msg.probability = dict(all_proba)[matched] / sum(dict(all_proba).values())
        msg.candidates = candidates
        msg.probabilities = np.array([dict(all_proba)[c] for c in candidates])
        msg.probabilities /= msg.probabilities.sum()
        self.pub_debug.publish(msg)

        # verification result with json target
        if target_bin is None or target_bin == '':
            return
        proba = [
            (c,
             (weight[c]['bof'] * bof_objects_proba[c]) +
             (weight[c]['color'] * cfeature_objects_proba[c])
             ) for c in candidates
            ]
        matched = sorted(proba, key=lambda x: x[1])[-1][0]
        # compose msg
        msg = ObjectRecognition()
        msg.header.stamp = stamp
        msg.matched = matched
        msg.probability = dict(proba)[matched] / sum(dict(proba).values())
        msg.candidates = candidates
        msg.probabilities = np.array([dict(proba)[c] for c in candidates])
        msg.probabilities /= msg.probabilities.sum()
        self.pub.publish(msg)