from typing import Optional import cv2 from pymba import Frame # todo add more colours PIXEL_FORMATS_CONVERSIONS = { 'BayerRG8': cv2.COLOR_BAYER_RG2RGB, } def display_frame(frame: Frame, delay: Optional[int] = 1) -> None: """ Displays the acquired frame. :param frame: The frame object to display. :param delay: Display delay in milliseconds, use 0 for indefinite. """ print('frame {}'.format(frame.data.frameID)) # get a copy of the frame data image = frame.buffer_data_numpy() # convert colour space if desired try: image = cv2.cvtColor(image, PIXEL_FORMATS_CONVERSIONS[frame.pixel_format]) except KeyError: pass # display image cv2.imshow('Image', image) cv2.waitKey(delay)