# Detecting hallways using LaserScan data

Hello everyone, I am trying to detect hallways (two solid parallel lines) using laser data (sensor_msgs/LaserScan). Does anyone know of any ready to use ROS packages to get this job done.

If there are no ready to use packages, my other option is to use Hough transforms to detect straight lines and search for two parallel lines. To do this, I have converted sensor_msgs/LaserScan to sensor_msgs/PointCloud2. How do I access individual points so that I can discard the Z axis values and apply Hough transform by voting an accumulator. (I am assuming PointCloud2 is a message type and we can not access individual points) Do I need to convert it into some other form? If so how can I do that?

Any help is much appreciated. Thank you.

edit retag close merge delete

Sort by » oldest newest most voted

Thanks for the quick reply. Yes, what you said seems valid. However, I have a question, How do I apply hough's transform to laser data? for the equation r = x cos theta + y sin theta, I can get r value (range in laser message), theta (theta increments from the laser message). I am still left with two unknowns x and y.

I used hough's transforms on Images before as follows: I iterate over every pixel and for every edge pixel, I calculate theta using gradient, solve for r in r = x cos theta + y sin theta vote for r , theta in a accumulator. The (r, theta) that gets maximum votes are my hough parameters.

So, when I have two unknowns (x, y ) how can solve for the equation.

Edit: I found the answer. The laser messages are already in polar form. so, you have r and theta from it. Using r, theta find x = r * cos theta and y = r * sin theta. round of both x and y. Using opencv create an empty image (white image) - the image size depends on the accuracy/resolution you need, for every calculated x, y manipulate pixel at x,y to black pixel. By doing so, you will get a white image with black dots (walls/obstacles detected by the laser). Now, use the built in Hough transform from OpenCV and find the lines. In order to detect the hallway, select two strong lines whose slopes are equal.

more

I implemented Hough transform before and I am not sure OpenCV is required as you only need it for visualization. I think you can make in a easier way the debugging output using python with matplotlib. You will vote in a numpy 2D array then show it

I checked and it is true OpenCV has a Hough line detector, however I think it was design for images instead of a laser scan.

I would be very curious to see the code of how you implemented this and how efficient it is. It is possible? If you end up implementing your own linear Hough Transform extraction code, I'd avoid the point cloud message entirely. Because the Hough Transform you'd want to implement is inherently polar in nature it can be calculated faster if you keep the polar coordinates you get from the laser scan instead of converting them to Cartesian coordinates.

more

I was restricted to 300 characters. So I wrote as an answer please reply to that. Thanks.