# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

from labvision import images, camera

# + pycharm={"name": "#%%\n"}
cam = camera.Camera(0)
frame = cam.get_frame()
frame = images.bgr_to_gray(frame)

crop_result = images.crop_polygon(frame)


# + pycharm={"name": "#%%\n"}
def mean_im():
    ims = []
    for f in range(30):
        im = cam.get_frame()
        im = images.bgr_to_gray(im)
        im = images.crop_and_mask(im, crop_result.bbox, crop_result.mask)
        ims.append(im)
    mean_im = images.mean(ims)
    return mean_im


# + pycharm={"name": "#%%\n"}
im = mean_im()
images.display(im)

# + pycharm={"name": "#%%\n"}
images.ThresholdGui(im)

# + pycharm={"name": "#%%\n"}
threshold = images.threshold(im, 90)

# + pycharm={"name": "#%%\n"}
images.OpeningGui(threshold)

# + pycharm={"name": "#%%\n"}
images.display(images.gaussian_blur(im, (31, 31)))

# + pycharm={"name": "#%%\n"}
blur = images.gaussian_blur(im, (31, 31))
images.ThresholdGui(blur)

# + pycharm={"name": "#%%\n"}
threshold = images.threshold(blur, 70)
images.display(threshold)

# + pycharm={"name": "#%%\n"}
images.OpeningGui(threshold)

# + pycharm={"name": "#%%\n"}
opened = images.opening(threshold, (31, 31))
images.display(opened)

# + pycharm={"name": "#%%\n"}
com = images.center_of_mass(opened)

# + pycharm={"name": "#%%\n"}
imc = images.gray_to_bgr(im)
imc = images.draw_circle(imc, com[0], com[1], 5)
images.display(imc)

# + pycharm={"name": "#%%\n"}
contour = images.find_contours(opened)
imc = images.draw_contours(imc, contour)

# + pycharm={"name": "#%%\n"}
images.display(imc)

# + pycharm={"name": "#%%\n"}


StarcoderdataJupyterScriptsDedupFiltered