def decode_qr()

in deepracer_offroad_ws/qr_detection_pkg/qr_detection_pkg/qr_detection_node.py [0:0]


    def decode_qr(self, image):
        """Method that decodes the QR from input image and returns the
        waypoints as a dictionary.

        Args:
            image (Image): Input image to scan for QR codes.

        Returns:
            waypoints (Dictionary): Consisting of the waypoints decoded else returns an empty dict.
        """
        try:
            waypoints = dict()
            # Decrement the limit
            self.limit = max(self.limit - 1, 0)
            # Check if limit has been reached to stop an ongoing action delta.
            if self.limit == 0:
                self.ongoing_action = None
                self.limit = 1
            # Decode qrcodes using pyzbar
            qrcodes = pyzbar.decode(image)

            for qrcode in qrcodes:
                x, y, w, h = qrcode.rect
                # Decode the string in QR Code
                qrcode_info = qrcode.data.decode('utf-8')
                # coordinates of the top left bounding box corner.
                top_left_x = np.int(x)
                top_left_y = np.int(y)
                # coordinates of the bottom right bounding box corner.
                bottom_right_x = np.int(x + w)
                bottom_right_y = np.int(y + h)

                if constants.QRKeys.DEEPRACER in qrcode_info:
                    # Default waypoint type
                    waypoint_type = constants.QRKeys.WAYPOINT
                    qr_json_detected = self.parse_qr_json(qrcode_info)
                    ref_x, ref_y = \
                        self.calculate_cur_img_ref_point(top_left_x,
                                                         top_left_y,
                                                         bottom_right_x,
                                                         bottom_right_y,
                                                         qr_code_placement_loc=\
                                                         qr_json_detected[constants.QRKeys.POSITION])
                    waypoints[qr_json_detected[constants.QRKeys.WAYPOINT]] = \
                        {
                            constants.QRKeys.WAYPOINT: qr_json_detected[constants.QRKeys.WAYPOINT],
                            constants.QRKeys.POSITION: qr_json_detected[constants.QRKeys.POSITION],
                            constants.QRKeys.REFERENCE: [ref_x, ref_y],
                            constants.QRKeys.BOUNDING_BOX: [top_left_x,
                                                            top_left_y,
                                                            bottom_right_x,
                                                            bottom_right_y],
                            constants.QRKeys.TYPE: waypoint_type
                    }
                    self.get_logger().info(f"Detected waypoints: {waypoints}")
            return waypoints
        except Exception as ex:
            self.get_logger().error(f"Failed decode qr step: {ex}")
            # Destroy the ROS Node running in another thread as well.
            self.destroy_node()
            rclpy.shutdown()