PCL: cylinderes segmentation;point cloud - c++

I'm working on my graduation project which consist on segmenting a pillar in point cloudinto its different cylinderes.
First step i did is i extracted the whole cylinder englobing the pillar with PCL library cylinder-segmenting code(c++), wich is composed of the different existing cylinderes seperated by a little gap (as shown in the photo), what i have as proposition is to segment these cylinderes by those gaps the thing that i really have no idea how to code it and i didn't find similar thing on internet.
enter image description here
and thanks in advance for any help.

Related

PCL, SACSegmentation detecting spheres

I'm trying to find spheres from a point cloud with pcl::sacSegmentation using RANSAC. The cloud is scanned with an accurate terrestial scanner from one station. The cloud density is about 1cm. The best results so far are shown in the image below. As you can see the cloud contains 2 spheres (r=7,25cm) and a steel beam where the balls are attached.. I am able to find three sphere candidates whose inlier points are extracted from cloud in the image (You can see two circle shapes on the beam near the spheres).
Input point cloud. Inlier points extracted
So, it seems that I am close. Still the found sphere centers are too much (~10cm) away from the truth. Any suggestion how could I improve this? I have been tweaking the model parameters quite some time. Here are the parameters for the aforementioned results:
seg.setOptimizeCoefficients(true);
seg.setModelType(pcl::SACMODEL_SPHERE);
seg.setMethodType(pcl::SAC_RANSAC);
seg.setMaxIterations(500000);
seg.setDistanceThreshold(0.0020);
seg.setProbability(0.99900);
seg.setRadiusLimits(0.06, 0.08);
seg.setInputCloud(cloud);
I also tried to improve the results by including point normals in the model with no better results. Yet there are couple parameters more to adjust so there might be some combinations I had not tried.
I happily give you more information if needed.
Thaks
naikh0u
After some investigation I have come in to conclusion that I can't find spheres with SACSegmentation from a cloud that contains lot of other points that don't belong in any sphere shape. Like in my case the beam is too much for the algorithm.
Thus, I have to choose the points that show some potential being a part of a sphere shape. Also I think, I need to separate the points belonging in different spheres. I tested and saw that my code works pretty well if the input cloud has only sphere points for single sphere with some "natural" noise.
Some have solved this problem by first extracting all points belonging to planes and then searched for spheres. Others have used colors of the target (in case of camera) to extract only needed points.
Deleting plane points should work for my example cloud, but my application may have more complex shapes too so it may be too simple..
..Finally, I got satisfied results by clustering the cloud with pcl::EuclideanClusterExtraction and feeding the clusters for sphere search one by one.

Opencv - align sample image and testing image

I have been in the project of testing the images of sample products compared with a sample product image. I have come up with two approaches but there are problems encountered in each approach.
Method 1. Remove Background, Realign images according to features and then find the difference of two images by subtraction.
Problem: I am thinking about using template matching to extract the region of interest and save as a new picture. However, is it possible to use template matching to extract? I saw the sample provided by opencv can make a frame or rectangle around the matched object. So, it seems feasible for me to make it at the center in the new picture. If it is possible, what is the way of making a square matched as the center of a new picture? It seems a bit difficult as the matched rectangle may not be horizontal.
Method 2. Cascade Classifier Training: it seems I can train the classifier to know what bad images are and what good images are.
Problem: However, from the classifier detection sample by opencv, it was used to compare during a video. Is it possible to do so on images? Also, how could I adjust the sample error or the precision of the classifier detection?
If you have any other feasible suggestions, please kindly give me some advices on them. Thanks for your kind attention!!

Algorithm for calculating the volume of the part of point cloud

I am taking part in the project studies associated with clouds of points.
We have to create a web application. Whose task will be displaying point cloud from .ply file. And then select an area and calculate its volume. The algorithm of counting the volume is to be implemented in C ++. The only things we have is a file in .ply format and file with the XYZ-coordinates of all points. The cloud of points we get, is generated from a picture taken by a drone. For example, it is a cloud of points representing a mountainous area . Our task is to be able to select such one mountain and calculate its approximate volume taking into account an error +/-. The measurement does not have to be perfect but it has to be even close to the real volume of mountain. The volume has to be calculated from the flat surface at the lowest point of the mountain.
I have two questions for you.
-First, could you give me a clue, link or anything that would help me to find such an algorithm and the reasons why he is the best.
-Second, do any of you have idea what would be the best way to select some area from the rendered point cloud?
I was looking for this information . But I can not find anything that would be useful enough to use it in our project. Any tip or a document on the subject would be very useful ;)
"Volume" is not a clearly defined concept for a point cloud. There are very many ways to determine a surface, and there is no single answer. It would depend very much on what constraints were given for defining the surface of the point cloud.
A very simplistic approach would be simply to use the minimum and maximum coordinate values on all three axes, thereby giving the volume of a right rectangular parallelepiped that encloses all the points.
A much more complex approach would involve computing a minimum convex envelope. That is a nontrivial problem.
It would get even harder if you were trying to find an envelope that was not necessarily convex.
In any case, it is important to pin down exactly what is meant by "volume" before you can craft an effective algorithm to compute it.
As you are working with pointclouds generated "from a picture taking by a drone" (I'm assuming here that you mean something like: photogrammetric process over drone imagery):
First:
Take a look at:
This
Or try to develop yourself some approach based on octrees.
If you go for developing your own approach, and you want it in c++, take a look at:
This
and This
Second:
I'm not sure if I understand the question, but looks obvius to me that the best way to select the area of interest in order to perfmor the calculation is through user's interaction (let the user select points arround the area and compute over the remaining points between).
Extra:
Just In case you didn't know it yet, I recommend CloudCompare to everyone who is working on something PointCloud-related.
Hope this links could help you.

Estimate color distribution with Gaussian mixture model

I am trying to use two Gaussian mixtures with EM algorithm to estimate color distribution of a video frame. For that, I want to use two separate peaks in the color distribution as the two Gaussian means to facilitate the EM calculation. I have several difficulties with the implementation of these in OpenCV.
My first question is: how can I determine the two peaks? I've searched about peak estimation in OpenCV, but still couldn't find any seperate function. So I am going to determine two regions, then find their maximum values as peaks. Is this way correct?
My second question is: how to perform Gaussian mixture model with EM in OpenCV? As far as I know, the "cv::EM::predict" function could give me the index of the most probable mixture component. But I have difficulties with training EM. I've searched and found some other codes, but finding the correct parameters is too much difficult for. Could someone provide me any example code for this? Thank you in advance.
#ederman, try {OpenCV library location}\opencv\samples\cpp\em.cpp instead of the web link. I think the sample code in the link is out of date now. I have successfully compiled the sample code in OpenCV 2.3.1. It shouldn't be a problem for 2.4.2.
Good luck:)
My first question is: how can I determine the two peaks?
I would iterate through the range of sample values possible, and test when the does EM.predict(sample)[0] peaks.

GJK collision detection implementation from 2D to 3D

I apologize for the length of this question and give a pre-emptive thanks for anyone who reads through this!
So i've spent the last few days going over the GJK algorithm. I understand the general concepts behind it, and understand the most of the nitty gritties of its implementation in 2D thanks to the wonderful article by William Bittle at http://www.codezealot.org/archives/88 .
I've implemented his pseudo code (found at the end of the article) into my own c++ project, however i want to make a 3D implementation. My weakness comes into using the dot products to test the voronoi regions and the tripleProducts to get perpandicular lines. But im trying to read up more on that.
My problem comes down to the containsOrigin function. Im having trouble visualizing and accounting for the new voronoi regions that the z axis adds. I just can't seem to wrap my head around how to determine which regions contains the origin. I assume there is 4 I have to account for, each extending from the triangular planes that the comprise the 4 faces of the tetrahedron simplex. If the origin is not within any of those regions, then it is contained, and we have a collision.
How do i go about testing if it is contained in a particular voronoi region/ which triangular face is pointing in the direction of the origin?
The current 2D algorithm checks if a triangle is made, if not, then the simplex is a line and it finds the 3rd point. I assume the 3D algorithm with check if a tetrahedron is made, if not, then it will check for a triangle, if true then it will to find a 4th point to make a tetrahedron(how would i get this? using a normal in direction of origin?). If i trangle isnt made, it will find a 3rd point to make a triangle (do i still use triple product for this like in 2D?).
Any suggestions, outlines, resources, code augmentations, comments are much appretiated.
Depending on what result you expect from the GJK algorithm you might want to look at this nice tutorial from Molly Rocket: https://mollyrocket.com/849
Be aware though that his implementation only outputs intersection? yes/no. But it might be a nice start.