<commit_before>from time import sleep
import cv2
from pymba import Vimba, Frame


def process_frame(frame: Frame):
    """
    Process the streaming frames. Consider sending the frame data to another thread/process if this is long running to
    avoid dropping frames.
    """
    print(f'frame {frame.data.frameID} callback')

    # get a copy of the frame data
    image = frame.buffer_data_numpy()

    # display image
    cv2.imshow('Image', image)
    cv2.waitKey(1)


if __name__ == '__main__':

    with Vimba() as vimba:
        camera = vimba.camera(0)
        camera.open()

        # arm the camera and provide a function to be called upon frame ready
        camera.arm('Continuous', process_frame)
        camera.start_frame_acquisition()

        # stream images for a while...
        sleep(5)

        # stop frame acquisition
        # start_frame_acquisition can simply be called again if the camera is still armed
        camera.stop_frame_acquisition()
        camera.disarm()

        camera.close()
<commit_msg>note on displaying cv2 windows from a thread<commit_after>from time import sleep
import cv2
from pymba import Vimba, Frame


def process_frame(frame: Frame):
    """
    Process the streaming frames. Consider sending the frame data to another thread/process if this is long running to
    avoid dropping frames.
    """
    print(f'frame {frame.data.frameID} callback')

    # get a copy of the frame data
    image = frame.buffer_data_numpy()

    # display image
    # note that this function is called in a thread, and therefore cv2 windows must be destroyed by the same thread
    cv2.imshow('Image', image)
    cv2.waitKey(1)


if __name__ == '__main__':

    with Vimba() as vimba:
        camera = vimba.camera(0)
        camera.open()

        # arm the camera and provide a function to be called upon frame ready
        camera.arm('Continuous', process_frame)
        camera.start_frame_acquisition()

        # stream images for a while...
        sleep(5)

        # stop frame acquisition
        # start_frame_acquisition can simply be called again if the camera is still armed
        camera.stop_frame_acquisition()
        camera.disarm()

        camera.close()

{'fraction_non_alphanumeric': 0.07501129688206055, 'fraction_numerical': 0.0063262539539087215, 'mean_word_length': 2.708542713567839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '1685705', 'n_tokens_mistral': 635, 'n_tokens_neox': 609, 'n_words': 231}