<jupyter_start><jupyter_text>First, we create our camera class like this.  Please note, you can only create one USBCamera instance.<jupyter_code>from jetcam.usb_camera import USBCamera

camera = USBCamera(width=224, height=224, capture_width=640, capture_height=480, capture_device=1)<jupyter_output><empty_output><jupyter_text>We can then capture a frame from the camera like this<jupyter_code>image = camera.read()

print(image.shape)<jupyter_output><empty_output><jupyter_text>Calling ``read`` also updates the camera's internal ``value``<jupyter_code>print(camera.value.shape)<jupyter_output><empty_output><jupyter_text>You can create a widget to display this image.  You'll need to convert from bgr8 format to jpeg to stream to browser<jupyter_code>import ipywidgets
from IPython.display import display
from jetcam.utils import bgr8_to_jpeg

image_widget = ipywidgets.Image(format='jpeg')

image_widget.value = bgr8_to_jpeg(image)

display(image_widget)<jupyter_output><empty_output><jupyter_text>You can set the ``running`` value of the camera to continuously update the value in background.  This allows you to attach callbacks to the camera value changes.<jupyter_code>camera.running = True

def update_image(change):
    image = change['new']
    image_widget.value = bgr8_to_jpeg(image)
    
camera.observe(update_image, names='value')<jupyter_output><empty_output><jupyter_text>You can unattach the callback like this<jupyter_code>camera.unobserve(update_image, names='value')<jupyter_output><empty_output><jupyter_text>You can also use the traitlets ``dlink`` method to connect the camera to the widget, using a transform inbetween<jupyter_code>import traitlets

camera_link = traitlets.dlink((camera, 'value'), (image_widget, 'value'), transform=bgr8_to_jpeg)<jupyter_output><empty_output><jupyter_text>You can remove this link like this<jupyter_code>camera_link.unlink()<jupyter_output><empty_output><jupyter_text>And reconnect it like this<jupyter_code>camera_link.link()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09424603174603174, 'fraction_numerical': 0.008928571428571428, 'mean_word_length': 8.650717703349283, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '62331', 'license': 'MIT', 'n_tokens_mistral': 683, 'n_tokens_neox': 660, 'n_words': 157, 'path': 'notebooks/usb_camera/usb_camera.ipynb', 'repo_name': 'HorusMaster/jetcamVideoStream', 'size': '2016'}