Click here to Skip to main content
15,400,433 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a point cloud stored in a text file in the form of x and y . I need to find multiple lines representing each side for the shown point cloud using ransac so that I can split the points representing inliers for each line. How can I do that using ransac in python ? The code I tried gives me bad results! So I want a better technique

What I have tried:

import matplotlib.pyplot as plt
import numpy as np
from sklearn import linear_model, datasets
from skimage.measure import LineModelND, ransac
import pandas as pd
import math
def plot_ransac(segment_data_x, segment_data_y):
    data = np.column_stack([segment_data_x, segment_data_y])
    model_robust, inliers = ransac(data, min_samples=5,residual_threshold=5, max_trials=500)
def distance(x1,y1,x2,y2):
    return np.sqrt((x1-x2)**2 + (y1-y2)**2)
x,y = np.loadtxt('D:/Point cloud data/Data mabna 4/Data_without_RGB/Downsampled/Walls_only_downsampled_5cm.txt', unpack=True)
x_data =  np.array(x)
y_data =  np.array(y)
x_segments = []
y_segments = []
distances = []
start = 0
for i in range(len(x_data)-1):
    distance_to_point = distance(x_data[i], y_data[i], x_data[i+1], y_data[i+1])
    if distance_to_point > 5:
        if i-start>10:
        start = i+1
    if i == len(x_data)-2:
        if i-start>10:

# plt.plot(x_data, y_data, '.', color = 'grey')
for x_seg, y_seg in zip(x_segments, y_segments):
    plt.plot(x_seg, y_seg,'.', markersize = 5)
#     plot_ransac(x_seg, y_seg)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900