def capture_video_frame(self, buffer_=None, filename=None, timeout=None):
"""Capture a single frame from video. Type :class:`numpy.ndarray`.
Video mode must have been started previously otherwise a :class:`ZWO_Error` will be raised. A new buffer
will be used to store the image unless one has been supplied with the `buffer` keyword argument.
If `filename` is not ``None`` the image is saved using :py:meth:`PIL.Image.Image.save()`.
:func:`capture_video_frame()` will wait indefinitely unless a `timeout` has been given.
The SDK suggests that the `timeout` value, in milliseconds, should be twice the exposure plus 500 ms."""
data = self.get_video_data(buffer_=buffer_, timeout=timeout)
whbi = self.get_roi_format()
shape = [whbi[1], whbi[0]]
if whbi[3] == ASI_IMG_RAW8 or whbi[3] == ASI_IMG_Y8:
img = np.frombuffer(data, dtype=np.uint8)
elif whbi[3] == ASI_IMG_RAW16:
img = np.frombuffer(data, dtype=np.uint16)
elif whbi[3] == ASI_IMG_RGB24:
img = np.frombuffer(data, dtype=np.uint8)
shape.append(3)
else:
raise ValueError('Unsupported image type')
img = img.reshape(shape)
if filename is not None:
from PIL import Image
mode = None
if len(img.shape) == 3:
img = img[:, :, ::-1] # Convert BGR to RGB
if whbi[3] == ASI_IMG_RAW16:
mode = 'I;16'
image = Image.fromarray(img, mode=mode)
image.save(filename)
logger.debug('wrote %s', filename)
return img
评论列表
文章目录