Пример #1
0
    def recognize_srv_call(self, roi_image):
        """
        Method that calls the Recognize.srv
        :param roi_image: Selected roi_image by the user
        """
        try:
            result = self._srv(
                image=self.bridge.cv2_to_imgmsg(roi_image, "bgr8"))
        except Exception as e:
            warning_dialog("Service Exception", str(e))
            return

        print result

        for r in result.recognitions:
            text_array = []
            best = CategoryProbability(
                label="unknown",
                probability=r.categorical_distribution.unknown_probability)
            for p in r.categorical_distribution.probabilities:
                text_array.append("%s: %.2f" % (p.label, p.probability))
                if p.probability > best.probability:
                    best = p

            self._image_widget.add_detection(r.roi.x_offset, r.roi.y_offset,
                                             r.roi.width, r.roi.height,
                                             best.label)

            if text_array:
                option_dialog(
                    "Classification results (Unknown probability=%.2f)" %
                    r.categorical_distribution.unknown_probability,
                    text_array)  # Show all results in a dropdown
Пример #2
0
    def image_roi_callback(self, roi_image):
        """
        Callback triggered when the user has drawn an ROI on the image
        :param roi_image: The opencv image in the ROI
        """
        if not self.labels:
            warning_dialog("No labels specified!", "Please first specify some labels using the 'Edit labels' button")
            return

        height, width = roi_image.shape[:2]

        option = option_dialog("Label", self.labels)
        if option:
            self._image_widget.add_detection(0, 0, width, height, option)
            self._stage_recognition(self._image_widget.get_roi(), option)
    def image_roi_callback(self, roi_image):
        if self._srv is None:
            warning_dialog(
                "No service specified!",
                "Please first specify a service via the options button (top-right gear wheel)"
            )
            return

        try:
            result = self._srv(
                image=self.bridge.cv2_to_imgmsg(roi_image, "bgr8"))
        except Exception as e:
            warning_dialog("Service Exception", str(e))
            return

        text_array = [
            "%s: %.2f" % (r.label, r.probability) for r in result.recognitions
        ]

        if text_array:
            self._image_widget.set_text(
                text_array[0])  # Show first option in the image
            option_dialog("Classification results",
                          text_array)  # Show all results in a dropdown
Пример #4
0
    def classify_srv_call(self, roi_image):
        """
        Method that calls the Classify2D.srv
        :param roi_image: Selected roi_image by the user
        """
        try:
            images = []
            image = self.bridge.cv2_to_imgmsg(roi_image, "bgr8")
            images.append(image)
            result = self._srv(images)
        except Exception as e:
            warning_dialog("Service Exception", str(e))
            return

        # we send one image, so we get max. one result
        if len(result.classifications) == 0:
            return

        c = result.classifications[0]
        text_array = []
        best = ObjectHypothesis(id=0, score=0.0)

        for r in c.results:
            if len(self.id_label_list) >= r.id:
                text_array.append("%s: %.2f" %
                                  (self.id_label_list.get(str(r.id)), r.score))
            else:
                text_array.append("%s: %.2f" % ("no_label", r.score))
            if r.score > best.score:
                best = r

        self._image_widget.add_detection(0, 0, 1, 1, str(best.id))

        if text_array:
            option_dialog("Classification results",
                          text_array)  # Show all results in a dropdown
Пример #5
0
    def image_roi_callback(self, roi_image):
        if not self.labels:
            warning_dialog(
                "No labels specified!",
                "Please first specify some labels using the 'Edit labels' button"
            )
            return

        self.roi_image = roi_image

        option = option_dialog("Label", self.labels)
        if option:
            self.label = option
            self._image_widget.set_text(option)

        self.store_image()
    def image_roi_callback(self, roi_image):
        """
        Callback from the image widget when the user has selected a ROI
        :param roi_image: The opencv image of the ROI
        """
        if not self.labels:
            warning_dialog(
                "No labels specified!",
                "Please first specify some labels using the 'Edit labels' button"
            )
            return

        height, width = roi_image.shape[:2]

        option = option_dialog("Label", self.labels)
        if option:
            self.label = option
            self._image_widget.add_detection(0, 0, width, height, option)
            self.annotate(roi_image)