def get_frame()

in projects/vision-ai-edge-camera-client/edge_camera.py [0:0]


    def get_frame(self, args, one_d, height, width):
        """Gets a sensor array dump from the camera and pre-processes.

        Args:
          args: program arguments.
          one_d: one dimensional array.
          height: image height.
          width: image width.

        Returns:
          PIL.Image: pre-processed image frame.
          self.frame_proto: protobuf frame.
        """
        if not height:
            one_d, height, width, _ = self.get_raw()
            if not height:
                if self.printout:
                    print("Genicam image acquiry failed")
                return None
        two_d = one_d.reshape(height, width)

        if args.range_max == 0:
            two_d_bits = np.interp(two_d, (two_d.min(), two_d.max()), (0, 254))
        else:
            two_d_bits = np.interp(
                two_d, (args.range_min, args.range_max), (0, 254)
            )

        if args.mode != "continuous" and self.printout:
            print(
                "Mapping from raw to 8bit: min: {}->{}, max: {}->{}".format(
                    two_d.min(), two_d_bits.min(), two_d.max(), two_d_bits.max()
                )
            )
        pil_image = Image.fromarray(
            two_d_bits.astype(np.uint8), mode="L"
        ).convert("RGB")
        if not self.protobuf:
            return pil_image

        buf = io.BytesIO()
        pil_image.save(buf, format="PNG")
        buf.seek(0)
        self.frame_proto.png_frame = buf.read()
        self.frame_proto.camera.CopyFrom(self.cam_proto)
        return self.frame_proto.SerializeToString().decode("utf-8")