Exemplo n.º 1
0
    def _fetch_data(self, timeout=5, debug=False):
        """Fetch data and recycle buffers."""
        try:
            ptr, length = SDK3.WaitBuffer(self.handle, timeout)
        except SDK3.TimeoutError as e:
            if debug:
                _logger.debug(e)
            return None

        raw = self.buffers.get()
        width = self._img_width
        height = self._img_height
        data = raw  # .reshape((-1, bytes_per_row))[:, 0:width].copy()
        data = np.empty((height, width), dtype="uint16")
        SDK3.ConvertBuffer(
            ptr,
            data.ctypes.data_as(DPTR_TYPE),
            width,
            height,
            self._img_stride,
            self._img_encoding,
            "Mono16",
        )
        # Requeue the buffer if buffer size has not been changed elsewhere.
        if raw.size == self._buffer_size:
            self.buffers.put(raw)
            SDK3.QueueBuffer(self.handle, ptr, length)
        else:
            del raw

        return data
Exemplo n.º 2
0
 def _create_buffers(self, num=None):
     """Create buffers and store values needed to remove padding later."""
     if self._buffers_valid:
         return
     if num is None:
         num = self.num_buffers
     self._purge_buffers()
     _logger.debug("Creating %d buffers.", num)
     self._img_stride = self._aoi_stride.get_value()
     self._img_width = self._aoi_width.get_value()
     self._img_height = self._aoi_height.get_value()
     self._img_encoding = self._pixel_encoding.get_string()
     img_size = self._image_size_bytes.get_value()
     self._buffer_size = img_size
     for i in range(num):
         buf = np.require(
             np.empty(img_size),
             dtype="uint8",
             requirements=["C_CONTIGUOUS", "ALIGNED", "OWNDATA"],
         )
         self.buffers.put(buf)
         SDK3.QueueBuffer(self.handle, buf.ctypes.data_as(DPTR_TYPE),
                          img_size)
     self._buffers_valid = True