Beispiel #1
0
        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)
        #print(bounding_box)
        cv2.rectangle(img_raw, bounding_box[0], bounding_box[1], (0, 255, 0),
                      2)
        # display stuff
        cv2.imshow('canny', combined_canny_edge)
        cv2.imshow('raw', img_raw)
        OTL_cut_out = img_deleted_background[
            bounding_box[0][1]:bounding_box[1][1],
            bounding_box[0][0]:bounding_box[1][0], :]
        cv2.imshow('cut_out', OTL_cut_out)
        # Possibility to save images
        if key == ord('s'):
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)