示例#1
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)
示例#2
0
# 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
    h_lines = parking_detection.lines_processing(lines)
    parking_detection.get_scatter(h_lines)
    x, y, n = parking_detection.hc()