blob: c5b7dbe952efbe183e67da59a5a303730a9c659d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
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)
|