Пример #1
0
import os.path
import matplotlib.pyplot as plt
from scipy.misc import imsave

# Our libraries
import city_segment
import parking_detection
import vehicle_segment

if __name__ == "__main__":

    filename = "example.jpg"

    # High level segmentation using pre-trained network
    if not os.path.isfile("output.npy"):
        city_segment.segmentation(filename, "output.png")

    # Create mask for only largest road segment
    mask = city_segment.largest_connected_component(filename="output.npy")
    #mask = city_segment.dilation(mask, 200)

    # Apply traditional CV to masked image
    img = cv2.imread(filename)
    lines = parking_detection.get_lines(img, mask, [1, 0.001, 10, 60, 40])
    #line_image = parking_detection.draw_lines(img, lines)

    # Detect vehicles in image
    car_lines = vehicle_segment.segmentation(filename)
    line_image = parking_detection.draw_lines(img, car_lines)

    # Post-processing on lines
Пример #2
0
    # Preprocessing for without shadow
    gray1 = cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
    blur1 = cv2.medianBlur(gray1, 11)
    ret, th3shadow = cv2.threshold(blur1, 100, 255, cv2.THRESH_BINARY)
    th3 = cv2.medianBlur(th3shadow, 5)

    # Canny edge detector
    cannyed_image_shadow = cv2.Canny(th3, 10, 250)

    # Preprocessing for canny with shadow
    gray = cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
    blur = cv2.medianBlur(gray, 5)

    cannyed_image = cv2.Canny(blur, 75, 250)

    # Road only mask
    if not os.path.isfile("output.npy"):
        city_segment.segmentation("example.jpg", "Outputs/output.jpg")
    mask = city_segment.largest_connected_component()

    # Apply mask
    canny_road1 = cv2.bitwise_and(cannyed_image_shadow, mask)
    canny_road2 = cv2.bitwise_and(cannyed_image, mask)

    # Subtraction
    woshadow = canny_road2 - canny_road1

    # Show
    cv2.imshow("", woshadow)
    cv2.waitKey(-1)
            cv2.fillPoly(img, [pts], (0,0,255))
            #cv2.polylines(img, [pts], True, (0,0,255), 3)
        else:
            cv2.fillPoly(img, [pts],(0,255,0))


if __name__ == "__main__":

    param=[1,0.001,10,60,40]
    filen="example.jpg"

    """
    rho=rho,theta=angle,threshold=thresh,lines=np.array([]),minLineLength=min_length,maxLineGap=max_gap)
    """
    if not os.path.isfile("output.npy"):
        city_segment.segmentation(filen, "output.jpg")

    segments = np.load("output.npy")

    mask_road = city_segment.largest_connected_component()
    img = cv2.imread(filen)

    # Apply traditional CV to masked image
    lines = get_lines(img,  mask_road.astype(np.uint8), param)
    h_lines = lines_processing(lines)
    get_scatter(h_lines)
    #print(np.shape(h_lines))
    X,y_hc,n_clust = hc()
    clust_lines = parking_spots(X,y_hc,n_clust)
    clust_lines = lines_processing(clust_lines)
    print(clust_lines)