<commit_before>from _opencv import ffi, lib


ESCAPE = ord("\x1b")


def fourcc((a, b, c, d)):
    """
    Calculate a FourCC integer from the four characters.

    http://www.fourcc.org/

    """

    return (((((ord(d) << 8) | ord(c)) << 8) | ord(b)) << 8) | ord(a);


capture = lib.cvCreateCameraCapture(0)
size = lib.cvSize(
    int(lib.cvGetCaptureProperty(capture, lib.CV_CAP_PROP_FRAME_WIDTH)),
    int(lib.cvGetCaptureProperty(capture, lib.CV_CAP_PROP_FRAME_HEIGHT)),
)

writer = lib.cvCreateVideoWriter(
    "/Users/Julian/Desktop/testing123.mpeg",
    fourcc("PIM1"),
    30,
    size,
    1,
)


lib.cvNamedWindow("Example", lib.CV_WINDOW_AUTOSIZE)


def escape_is_not_pressed(milliseconds=20):
    return lib.cvWaitKey(milliseconds) != ESCAPE


cascade = lib.cvLoadHaarClassifierCascade(
    "/Users/Julian/Desktop/haarcascades/haarcascade_frontalface_default.xml",
    lib.cvSize(1, 1),
)

storage = lib.cvCreateMemStorage(0)


while escape_is_not_pressed():
    frame = lib.cvQueryFrame(capture)
    objects = lib.cvHaarDetectObjects(
        frame,
        cascade,
        storage,
        1.1,
        3,
        0,
        lib.cvSize(0, 0),
        lib.cvSize(0, 0),
    )
    for i in xrange(objects.total):
        rectangle = ffi.cast("CvRect*", lib.cvGetSeqElem(objects, i))

        top_point = ffi.new("CvPoint *", [rectangle.x, rectangle.y])
        bottom_point = ffi.new(
            "CvPoint *",
            [rectangle.x + rectangle.width, rectangle.y + rectangle.height],
        )

        lib.cvRectangle(
            frame,
            top_point[0],
            bottom_point[0],
            lib.cvScalar(255, 0, 0, 0),
            1,
            8,
            0,
        )

    lib.cvWriteFrame(writer, frame)
    lib.cvShowImage("Example", frame)<commit_msg>Use size to ignore noise.<commit_after>from _opencv import ffi, lib


ESCAPE = ord("\x1b")


def fourcc((a, b, c, d)):
    """
    Calculate a FourCC integer from the four characters.

    http://www.fourcc.org/

    """

    return (((((ord(d) << 8) | ord(c)) << 8) | ord(b)) << 8) | ord(a);


capture = lib.cvCreateCameraCapture(0)
size = lib.cvSize(
    int(lib.cvGetCaptureProperty(capture, lib.CV_CAP_PROP_FRAME_WIDTH)),
    int(lib.cvGetCaptureProperty(capture, lib.CV_CAP_PROP_FRAME_HEIGHT)),
)

writer = lib.cvCreateVideoWriter(
    "/Users/Julian/Desktop/testing123.mpeg",
    fourcc("PIM1"),
    30,
    size,
    1,
)


lib.cvNamedWindow("Example", lib.CV_WINDOW_AUTOSIZE)


def escape_is_not_pressed(milliseconds=20):
    return lib.cvWaitKey(milliseconds) != ESCAPE


cascade = lib.cvLoadHaarClassifierCascade(
    "/Users/Julian/Desktop/haarcascades/haarcascade_frontalface_default.xml",
    lib.cvSize(1, 1),
)

storage = lib.cvCreateMemStorage(0)


while escape_is_not_pressed():
    frame = lib.cvQueryFrame(capture)
    objects = lib.cvHaarDetectObjects(
        frame,
        cascade,
        storage,
        1.1,
        3,
        0,
        lib.cvSize(0, 0),
        lib.cvSize(0, 0),
    )
    for i in xrange(objects.total):
        rectangle = ffi.cast("CvRect*", lib.cvGetSeqElem(objects, i))
        width, height = rectangle.width, rectangle.height

        is_too_small_to_be_interesting = width * height < 10000
        if is_too_small_to_be_interesting:
            continue

        top_point = ffi.new("CvPoint *", [rectangle.x, rectangle.y])
        bottom_point = ffi.new(
            "CvPoint *", [rectangle.x + width, rectangle.y + height],
        )

        lib.cvRectangle(
            frame,
            top_point[0],
            bottom_point[0],
            lib.cvScalar(255, 0, 0, 0),
            1,
            8,
            0,
        )

    lib.cvWriteFrame(writer, frame)
    lib.cvShowImage("Example", frame)
{'fraction_non_alphanumeric': 0.13329778725673153, 'fraction_numerical': 0.020527859237536656, 'mean_word_length': 2.4934823091247673, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '3126249', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1297, 'n_words': 230}