Beispiel #1
0
        bool_motor = cv2.getTrackbarPos(string_motor, 'panel')

        lower_green = np.array([l_h, l_s, l_v])
        upper_green = np.array([u_h, u_s, u_v])
        # for live preview
        cv2.imshow('panel', panel)
        key = cv2.waitKey(20)
        # cut out background
        img_deleted_background, mask = image_processor.remove_background_youtube(
            img_raw, lower_green, upper_green)
        cv2.imshow('bckgrndsgmnttn', img_deleted_background)

        mask = cv2.blur(mask, (3, 3))
        img_gray = image_processor.gray(img_raw)
        # For possible future purposes
        mask_canny_edge = image_processor.canny(mask)
        img_canny_edge = image_processor.auto_canny(img_gray)
        mask_weight = 1.0
        combined_canny_edge = image_processor.combine_edges(
            mask_canny_edge, mask_weight, img_canny_edge, (1 - mask_weight))

        object_contour = image_processor.max_contour(combined_canny_edge)
        if key == ord('q'):
            cv2.destroyAllWindows()
            motor.cleanUp()
            quit()
        try:
            bounding_box = image_processor.bounding_box(object_contour)
        except:
            continue
        cv2.drawContours(img_raw, object_contour, -1, (0, 255, 0), 3)
Beispiel #2
0
from image_capture import ImageCapture
from image_processing import ImageProcessing
import cv2
import numpy as np

camera = ImageCapture()
#camera = cv2.VideoCapture(0)
processor = ImageProcessing()

while True:
    img_raw = camera.capture()
    img_cut = img_raw[:,
                      int(np.shape(img_raw)[1] * 1 /
                          5):int(np.shape(img_raw)[1] * 4 / 5), :]
    img_gray = processor.gray(img_cut)
    edge = processor.canny(img_gray)
    contour = processor.max_contour(edge)
    cv2.drawContours(img_cut, contour, -1, (0, 255, 0), 3)
    bounding_box = processor.bounding_box(contour)
    print(bounding_box)
    #if bounding_box != -1:
    #    print("success!")
    #else:
    #    print("failure!")
    cv2.imshow('raw_image', img_raw)
    cv2.imshow('cut_image', img_cut)
    cv2.imshow('gray_image', img_gray)
    cv2.imshow('canny_image', edge)
    cv2.waitKey(20)