Пример #1
0
def pipe_verbose():
    dir_name = 'camera_cal\calibration*.jpg'
    test_img = 'test_images\\test3.jpg'

    images_list = glob.glob(dir_name)
    test_image = cv2.imread(test_img)
    test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)
    # img = cv2.imread(dir_name)

    # number of the corners in the x axis and y axis
    nx = 9
    ny = 6
    objpoints, imgpoints = calibrate_camera(images_list, nx, ny, True)
    dst = calculate_undistord(test_image, objpoints, imgpoints, True)
    warp(dst, 'warped.png', True)

    sobel_x = abs_sobel_thresh(dst, 'x', 30, 100, True)
    sobel_y = abs_sobel_thresh(dst, 'y', 30, 100, True)
    mag_bin = mag_thresh(dst, 15, (30, 100), True)
    dir_bin = direction_threshold(dst, 15, (0.7, 1.3), True)
    comb = combining_tecniques(sobel_x, sobel_y, mag_bin, dir_bin, True)
    store_RGB_separately(dst, True)
    hls_img = convert_RGB_HLS(dst, True)
    color_merged, combined_bin = pipeline(dst, (90, 200), (30, 100), True)

    warped, MInv = warp(combined_bin, 'combined_bin_warped.png', True)
    # histogram(warped)

    left_lane_inds, right_lane_inds, left_fit, right_fit, left_fitx, right_fitx = sliding_window(
        warped, True)
    get_line_fit_from_pre_defined(warped, left_fit, right_fit, 100, True)
    draw_lane(dst, warped, left_fit, right_fit, MInv, True)

    return objpoints, imgpoints
Пример #2
0
    def laneDetect(self, img):
        img = cv2.resize(img, (self.frameWidth, self.frameHeight), None)

        imgUndis = utlis.undistort(img)
        img2, imgCanny, imgColor = utlis.thresholding(imgUndis)
        src = np.float32([(0.24, 0.55), (0.76, 0.55), (0.12, 1.0),
                          (0.88, 1.0)])
        img2 = utlis.perspective_warp(img2,
                                      dst_size=(self.frameWidth,
                                                self.frameHeight),
                                      src=src)
        imgSliding, curves, lanes, ploty = utlis.sliding_window(
            img2, 5, draw_windows=False)

        try:
            curverad = utlis.get_curve(img, curves[0], curves[1])
            lane_curve = np.mean([curverad[0], curverad[1]])
            img = utlis.draw_lanes(img,
                                   curves[0],
                                   curves[1],
                                   self.frameWidth,
                                   self.frameHeight,
                                   src=src)
            # ## Average
            currentCurve = lane_curve // 50

            if int(np.sum(self.arrayCurve)) == 0:
                averageCurve = currentCurve
            else:
                averageCurve = np.sum(
                    self.arrayCurve) // self.arrayCurve.shape[0]

            if abs(averageCurve - currentCurve) > 200:
                self.arrayCurve[self.arrayCounter] = averageCurve
            else:
                self.arrayCurve[self.arrayCounter] = currentCurve

            self.arrayCounter += 1

            if self.arrayCounter >= self.noOfArrayValues:
                self.arrayCounter = 0

            cv2.putText(img, str(int(averageCurve)),
                        (self.frameWidth // 2 - 70, 70),
                        cv2.FONT_HERSHEY_DUPLEX, 1.75, (0, 0, 255), 2,
                        cv2.LINE_AA)
            img = utlis.drawLines(img, lane_curve)
            return img, int(averageCurve)

        except Exception as ex:
            lane_curve = 00
            print(ex)
            pass
            img = utlis.drawLines(img, lane_curve)
            return img, 0
def convert_mat_to_np(limit=100, verbose=True):
    """
    Converts all the mat files in DATA_DIR into numpy files
    in NUMPY_DIR

    :param limit: The max number of files to convert
    :param verbose: bool to display progress information
    """

    for m, mat_file in enumerate(os.listdir(DATA_DIR)[:limit]):

        if verbose:
            print("Processing file: {0}, file {1}/{2}".format(
                mat_file, m + 1, len(os.listdir(DATA_DIR)[:limit])))
        if "blue" in mat_file:
            print("Blue file not normalized, skipping\n")
            continue

        mat = load_from_mat(mat_file)
        data = process_mat(mat)
        file_name = mat_file.split('.')[-2]

        X = []
        y = []
        for i, ts in enumerate(data):
            # Get the index for where the time series becomes classified as
            classifying_point = get_correct_y(ts)
            if classifying_point != -1:
                classifying_point -= 3
            for index, window in enumerate(
                    sliding_window(ts, window_size=WINDOW_SIZE)):
                X.append(window)
                if classifying_point == -1:
                    y.append(0)
                else:
                    y.append(1 if (index + WINDOW_SIZE -
                                   1) >= classifying_point else 0)
            if verbose and (i + 1) % 10 == 0:
                print("Processing fiber: {0}/{1}".format(i + 1, len(data)))
        if verbose:
            print("Finished processing {0}...\n".format(mat_file))

        X = np.array(X)
        y = np.array(y)

        # Randomly shuffle the data
        indices = np.arange(X.shape[0])
        np.random.shuffle(indices)

        X = X[indices]
        y = y[indices]

        save_to_np(X, y, file_name)
Пример #4
0
def wav_to_np(folder_path, window_size=100, slide_size=12):
    if folder_path[-1] != '/':
        folder_path += '/'

    X, Y, X_normal = [], [], []
    files = glob.glob(folder_path + '*.wav')
    for f in files:
        data, sample_frequency,encoding = wavread(f)
        X_normal.append(data[:, 0])
        data = np.array(list(util.sliding_window(data[:, 0], window_size,
                                                 slide_size)))
        f = f.split('/')[-1].split('_')[1]
        X.append(data)
        Y.append(f)

    return X, Y, X_normal
Пример #5
0
        result = result.intersection(s)
    return result

N = 25
M = 10000
KMeans_tr_size = 200000
D_atoms = 500
zoom_dim = 20
data_folder = sys.argv[1] 
output_folder = sys.argv[2]

if output_folder[-1] != '/':
    output_folder += '/'

X, Y = util.wav_to_np(data_folder)
X = [util.sliding_window(x, 40, 20) for x in X]

X = np.vstack(X)
X = X[np.random.permutation(len(X))]
X_Kmeans = X[:KMeans_tr_size]
D = KMeans(n_clusters=D_atoms, init_size=D_atoms*3)
D.fit(X_Kmeans)
D = D.cluster_centers_

D = util.normalize(D)
X = util.normalize(X)
D_mean = np.mean(D, axis=0)
D = D - D_mean
X = X - D_mean
U, S_D, V = np.linalg.svd(D)
_, S_X, _ = np.linalg.svd(X[:M])
Пример #6
0
def process_image(img):

    global objpoints
    global imgpoints
    global left_line
    global rigth_line

    dst = calculate_undistord(img, objpoints, imgpoints, False)
    color_merged, combined_bin = pipeline(dst, (90, 200), (30, 100), False)
    warped, MInv = warp(combined_bin, 'combined_bin_warped.png', False)

    if left_line.frame == 0:
        left_lane_inds, right_lane_inds, left_fit, right_fit, left_fitx, right_fitx = sliding_window(
            warped, False)
    else:
        left_lane_inds, right_lane_inds, left_fit, right_fit, left_fitx, right_fitx = get_line_fit_from_pre_defined(
            warped, left_line.mean_fit(), rigth_line.mean_fit(), 100, False)

    left_line.add_fit(left_fit)
    rigth_line.add_fit(right_fit)
    left_line.frame += 1
    rigth_line.frame += 1
    img = draw_lane(dst, warped, left_line.mean_fit(), rigth_line.mean_fit(),
                    MInv, False)
    curvature = np.mean(
        measure_curvatures(warped, left_line.mean_fit(),
                           rigth_line.mean_fit()))
    car_offset = measure_car_offset(warped, left_line.mean_fit(),
                                    rigth_line.mean_fit())
    font = cv2.FONT_HERSHEY_SIMPLEX
    cv2.putText(img,
                'Radius of the Curvature = ' + str(int(curvature)) + '(m)',
                (50, 100), font, 2, (255, 255, 255), 2, cv2.LINE_AA)
    cv2.putText(img, 'Offset = ' + str(round(car_offset, 2)) + '(m)',
                (50, 150), font, 2, (255, 255, 255), 2, cv2.LINE_AA)
    result = img

    return result
Пример #7
0
linewidth = 2
fig_name = 'boosted_dim'
KMeans_tr_size = 200000
D_atoms = 500
ws = 50
subsample_pcts = [1., 1., 1., 0.5]

X_flat, Y = util.wav_to_np('/home/brad/data/robot/')
X = []

num_folds = 10
sss = StratifiedShuffleSplit(Y, num_folds, test_size=0.7, random_state=0)

for x in X_flat:
    X.append(util.sliding_window(x, ws, 5))

plt_dict = {}
features = [2, 5, 10, 20]
nodes = [1, 2, 5, 10, 15, 20]

for f in features:
    plt_dict[f] = []
    for n in nodes:
        print f, n
        accs = []
        for train_index, test_index in sss:
            X_train = [X[i] for i in train_index]
            X_test = [X[i] for i in test_index]
            bnn = BoostedNN(D_atoms, n, f)
            bnn.fit(X_train, Y[train_index])