├── README.md ├── code ├── Object detection.py ├── Selection of ROI.py ├── las to pcd with UI.py └── las2pcd.py └── output └── Final output.jpg /README.md: -------------------------------------------------------------------------------- 1 | # Object-Detection-using-LiDAR 2 | 3 | This repo refers to object detection using LiDAR data specifically LAS and LAZ formats. 4 | 5 | Main libraries used in this project: 6 | 7 | 1. laspy 8 | 9 | 2. Keras 10 | 11 | 3. pytorch 12 | 13 | 4. numpy 14 | 15 | 5. scipy 16 | 17 | 6. pcl 18 | 19 | Output is shown below as a jpeg format (screenshot of the output LiDAR .las file) 20 | 21 | 22 | 23 | 24 | ![Object detection](https://github.com/niranjanreddy891/Object-Detection-using-LiDAR/blob/master/output/Final%20output.jpg) 25 | 26 | 27 | Note: 28 | 29 | 30 | # In the next release, I want to display the name of the object like person, vehicle, trees and roads by Name if possible to show accuracy in percentage. 31 | -------------------------------------------------------------------------------- /code/Object detection.py: -------------------------------------------------------------------------------- 1 | # author: niranjanreddy891@gmail.com 2 | 3 | 4 | import numpy as np 5 | import random 6 | import scipy as sc 7 | from laspy import file 8 | import pcl 9 | from pcl import pcl_visualization 10 | import tkinter 11 | import tkinter as tk 12 | from tkinter.filedialog import askopenfilename 13 | import tensorflow as tf 14 | import keras 15 | 16 | def browseFile1(): 17 | global inFile1 18 | inFile1=askopenfilename() 19 | txt1.insert(0.0, inFile1) 20 | root = tk.Tk() 21 | root.title("Visualization tool") 22 | Label = tk.Label(root, text="Select a LAS file") 23 | Label.grid(row = 1, column = 0, columnspan = 30) 24 | 25 | 26 | browseButton1 = tk.Button(root,text="Browse", command=browseFile1) 27 | browseButton1.grid(row = 2, column = 2) 28 | 29 | txt1 = tk.Text(root, width = 60, height = 1) 30 | txt1.grid(row = 2, column = 0, columnspan = 2) 31 | 32 | def on_click(): 33 | f = file.File(inFile1,mode='r') 34 | ptcloud = np.vstack((f.x, f.y, f.z)).transpose() 35 | f.close() 36 | 37 | # Centred the data 38 | ptcloud_centred = ptcloud - np.mean(ptcloud, 0) 39 | 40 | # Simulate an intensity information between 0 and 1 41 | ptcloud_centred = sc.append(ptcloud_centred, np.zeros((ptcloud.shape[0], 1)), axis=1) # Ajout d'une ligne (axis=0) 42 | for i in range(ptcloud_centred.shape[0] - 1): 43 | ptcloud_centred[i, 3] = random.random() 44 | 45 | p = pcl.PointCloud_PointXYZI() 46 | p.from_array(np.array(ptcloud_centred, dtype=np.float32)) 47 | 48 | visual = pcl_visualization.CloudViewing() 49 | visual.ShowGrayCloud(p) 50 | def check_was_stopped(): 51 | visual.WasStopped() 52 | 53 | root.after(100, check_was_stopped) 54 | check_was_stopped() 55 | #laspy librairy, read las file 56 | 57 | label = tk.Label(root) 58 | label.grid() 59 | 60 | tk.Button(text="Visualize", command=on_click).grid() 61 | 62 | 63 | root.geometry('600x130') 64 | root.mainloop() 65 | -------------------------------------------------------------------------------- /code/Selection of ROI.py: -------------------------------------------------------------------------------- 1 | # author: niranjanreddy891@gmail.com 2 | 3 | 4 | import numpy as np 5 | import random 6 | import scipy as sc 7 | from laspy import file 8 | import tkinter 9 | import tkinter as tk 10 | from tkinter.filedialog import askopenfilename 11 | import pclpy 12 | from pclpy import pcl 13 | from tkinter import * 14 | import tensorflow as tf 15 | import keras 16 | 17 | 18 | def browseFile1(): 19 | global inFile1 20 | inFile1=askopenfilename() 21 | txt1.insert(0.0, inFile1) 22 | root = tk.Tk() 23 | root.title("Selection of ROI") 24 | Label = tk.Label(root, text="Select a LAS/LAZ file") # both las and laz file support 25 | Label.grid(row = 1, column = 0, columnspan = 30) 26 | 27 | 28 | browseButton1 = tk.Button(root,text="Browse", command=browseFile1) 29 | browseButton1.grid(row = 2, column = 2) 30 | 31 | txt1 = tk.Text(root, width = 80, height = 1) 32 | txt1.grid(row = 2, column = 0, columnspan = 2) 33 | 34 | def on_click(): 35 | def ROI_window(): 36 | offset = pclpy.io.las.get_offset(inFile1) 37 | pc = pclpy.io.las.read(inFile1, "PointXYZRGBA", xyz_offset=offset) 38 | viewer = pcl.visualization.PCLVisualizer("viewer", True) 39 | viewer.addPointCloud(pc) 40 | viewer.resetCamera() 41 | 42 | viewers = [viewer] 43 | 44 | def handle_event_area(event): 45 | # use x to toggle rectangle selection 46 | assert isinstance(event, pcl.visualization.AreaPickingEvent) 47 | indices = pcl.vectors.Int() 48 | event.getPointsIndices(indices) 49 | 50 | other_viewer = pcl.visualization.PCLVisualizer("viewer", True) 51 | rgb = np.array([pc.r[indices], pc.g[indices], pc.b[indices]]).T 52 | other_pc = pcl.PointCloud.PointXYZRGBA.from_array(pc.xyz[indices], rgb) 53 | other_viewer.addPointCloud(other_pc) 54 | other_viewer.resetCamera() 55 | viewers.append(other_viewer) 56 | 57 | viewer.registerAreaPickingCallback(handle_event_area) 58 | 59 | while not all(v.wasStopped() for v in viewers): 60 | for v in viewers: 61 | if not v.wasStopped(): 62 | v.spinOnce(50) 63 | 64 | ROI_window() 65 | 66 | 67 | label = tk.Label(root) 68 | label.grid() 69 | 70 | tk.Button(text="Visualize", command=on_click).grid() 71 | 72 | 73 | root.geometry('730x140') 74 | root.mainloop() 75 | 76 | ############################################################################# 77 | 78 | -------------------------------------------------------------------------------- /code/las to pcd with UI.py: -------------------------------------------------------------------------------- 1 | # author: niranjanreddy891@gmail.com 2 | 3 | 4 | import numpy as np 5 | import random 6 | import scipy as sc 7 | from laspy import file 8 | import pcl 9 | from pcl import pcl_visualization 10 | import tkinter 11 | import tkinter as tk 12 | from tkinter.filedialog import askopenfilename 13 | 14 | 15 | def browseFile1(): 16 | global inFile1 17 | inFile1=askopenfilename() 18 | txt1.insert(0.0, inFile1) 19 | root = tk.Tk() 20 | root.title("Visualization tool") 21 | Label = tk.Label(root, text="Select a LAS file") 22 | Label.grid(row = 1, column = 0, columnspan = 30) 23 | 24 | 25 | browseButton1 = tk.Button(root,text="Browse", command=browseFile1) 26 | browseButton1.grid(row = 2, column = 2) 27 | 28 | txt1 = tk.Text(root, width = 60, height = 1) 29 | txt1.grid(row = 2, column = 0, columnspan = 2) 30 | 31 | def on_click(): 32 | f = file.File(inFile1,mode='r') 33 | ptcloud = np.vstack((f.x, f.y, f.z)).transpose() 34 | f.close() 35 | 36 | # Centred the data 37 | ptcloud_centred = ptcloud - np.mean(ptcloud, 0) 38 | 39 | # Simulate an intensity information between 0 and 1 40 | ptcloud_centred = sc.append(ptcloud_centred, np.zeros((ptcloud.shape[0], 1)), axis=1) # Adjusting axis (axis=0) 41 | for i in range(ptcloud_centred.shape[0] - 1): 42 | ptcloud_centred[i, 3] = random.random() 43 | 44 | p = pcl.PointCloud_PointXYZI() 45 | p.from_array(np.array(ptcloud_centred, dtype=np.float32)) 46 | 47 | visual = pcl_visualization.CloudViewing() 48 | visual.ShowGrayCloud(p) 49 | def check_was_stopped(): 50 | visual.WasStopped() 51 | 52 | root.after(100, check_was_stopped) 53 | check_was_stopped() 54 | #laspy librairy, read las file 55 | 56 | label = tk.Label(root) 57 | label.grid() 58 | 59 | tk.Button(text="Visualize", command=on_click).grid() 60 | 61 | 62 | root.geometry('1000x600') 63 | root.mainloop() 64 | -------------------------------------------------------------------------------- /code/las2pcd.py: -------------------------------------------------------------------------------- 1 | # author: niranjanreddy891@gmail.com 2 | 3 | 4 | from laspy.file import File 5 | import numpy as np 6 | 7 | inFile = File('E:/Lidar-practice/new-files/las14_type7_ALS_RIEGL_Q680i.las', mode='r') 8 | 9 | I = inFile.Classification == 2 10 | 11 | outFile = File('E:/Lidar-practice/new-files/tttttttttttt.pcd', mode='w', header=inFile.header) 12 | outFile.points = inFile.points[I] 13 | outFile.close() 14 | -------------------------------------------------------------------------------- /output/Final output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niranjanreddy891/Object-Detection-using-LiDAR/8b5e335c0aad80458cd315d5ed1b781dd18ebb12/output/Final output.jpg --------------------------------------------------------------------------------