示例#1
0
def process_video(video_path):
    detector = initialize_detector()

    input_shape = (48, 48, 3)
    num_classes = 4
    cnn_weights_path = 'model/weights.h5'
    DELTA = 15

    dataset = Dataset()
    cnn = Model(input_shape, num_classes, cnn_weights_path)

    cap = cv2.VideoCapture(video_path)

    while (cap.isOpened()):
        _, frame = cap.read()

        frame = resize(frame, (NEW_HEIGHT, NEW_WIDTH), mode='constant')
        print(frame.shape)

        predictions = hot_predict('dummy', detector, image=frame)

        for bounding_box in predictions:
            x1 = int(bounding_box['x1']) - DELTA
            y1 = int(bounding_box['y1']) - DELTA
            x2 = int(bounding_box['x2']) + DELTA
            y2 = int(bounding_box['y2']) + DELTA

            traffic_sign = frame[y1:y2, x1:x2]
            processed_image = dataset._preprocess_image(traffic_sign,
                                                        centered=True)

            cnn_input = np.expand_dims(processed_image, axis=0)

            label = cnn.predict(cnn_input)
            draw_rectangle(frame, (x1, y1, x2, y2), label)

        cv2.imshow('frame', frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()
示例#2
0
    args = parser.parse_args()

    predictions = detect_traffic_signs(args.image)
    image = imread(args.image)

    input_shape = (48, 48, 3)
    num_classes = 4
    cnn_weights_path = 'model/weights.h5'
    DELTA = 15

    dataset = Dataset()
    cnn = Model(input_shape, num_classes, cnn_weights_path)

    for bounding_box in predictions:
        x1 = int(bounding_box['x1']) - DELTA
        y1 = int(bounding_box['y1']) - DELTA
        x2 = int(bounding_box['x2']) + DELTA
        y2 = int(bounding_box['y2']) + DELTA

        traffic_sign = image[y1:y2, x1:x2]
        processed_image = dataset._preprocess_image(traffic_sign,
                                                    centered=True)

        cnn_input = np.expand_dims(processed_image, axis=0)

        label = cnn.predict(cnn_input)
        draw_rectangle(image, (x1, y1, x2, y2), label)

    plt.imshow(image)
    plt.show()