Create an updating html table that is displayed while the video is captured.
import cv2
from pandas import Series, DataFrame
from ipywidgets import HTML
table = HTML()
def show_webcam(mirror=False):
global df
cam = cv2.VideoCapture(0)
while True:
ret_val, img = cam.read()
if mirror:
img = cv2.flip(img, 1)
df = DataFrame(img[None, None, 3][0, 0, :, :], columns=list('rgb'))
table.value = df.describe().astype(str).to_html()
cv2.imshow('my webcam', img)
if cv2.waitKey(1) == 27:
break # esc to quit
cv2.destroyAllWindows()
def main():
try:
__import__("IPython").display.display(table)
show_webcam(mirror=True)
except KeyboardInterrupt: ...
if __name__ == '__main__':
main()