Find radius from centroid - ruby-on-rails

I'm converting a KML file to a polygon stored on my database thanks to RGeo
I need the centroid: #area.centroid and I would like to find the approximative radius on my shape.
I don't know if it's possible. My database field is a geometry. That means I can store polygons AND multi-polygons. The type of my area is RGeo::Geos::CAPIMultiPolygonImpl
Finally I think I need the check if the area is a simple polygon or a multiple. If it's a simple one, I would like to find the radius. Else nothing.
Thank you for your help !

I finally did like below:
Convexe Hull
Centroid of this Convexe Hull
minimum distance between Convexe Hull points (thanks to exterior_ring function) and the centroid
By the way I don't know why I had to take the minimum. It was to adapt my scale. I don't really understand how the centroid of a polygon (which could have really strange shape) can be found.
Anyway, it's working thanks to the 3 steps written previously.

Related

Draw epipolar lines for spherical images with known pose

I have a couple of spherical images, given in equirectangular projection, looking at the same object from different positions. I know the absolute pose of each image e.g. position in geographical coordinates and roll/pitch/yaw angles. Given the pixel coordinate of a point in one image I would like to find a way to draw the epipolar line (where the correspondent point lies) in the other one.
I tried to deal with Essential/Fundamental matrix in python using OpenCV but I did'nt figure out how to achieve this.
Any help is really appreciated.
Thanks

Is it possible to perspectivetransform an ellipse into a circle?

For a project, I need to store circles detected on some photos. The problem is that some of these photos are taken from an angle, meaning the circles are ellipses. Is it possible to somehow turn the ellipses into circles?
I thought of rectifying the ellipse, then transforming the rectangle to a square. Indeterminate problem comes to my mind, meaning there are too many possible variations for my approach, and the results are different for each approach.
To find perspective transform, you need to have 4 pairs of corresponding coordinates: points at distorted picture and their ideal positions after correction of perspective.
In this case you can calculate matrix of perspective transform with getPerspectiveTransform function and apply it to correct all the picture. Example

How to find the direction of an "L" shape in a image

I need to find the moving direction of a vehicle by its extracted point cloud, and I have converted the point cloud to the following image.
As the target vehicle could be moving straight or turning and the image is sometimes clear and sometimes fuzzy, I find it's difficult to match the "L" shape using template matching.
I also try to use RANSAC to fit the linear, but it has two sides and RANSAC does not work well. What I need to do is using an oriented bounding box to represent the vehicle.
If I could have the yaw angle of the "L" shape, it's very easy to recover it to an oriented bounding box. So could anyone give me some suggestions?
PS: The function cv::minAreaRect could offer a basic result, but it sometimes fit the "L" shape in a wrong direction.
Build the convex hull and qualify the sides as "pretty vertical" and "pretty horizontal". This will help you identify the corners.
A yet simpler method is to identify the four pixels that maximimze ±X±Y. This gives you an interesting bounding quadrilateral (often reduced to a triangle).
One possibility is to see what side is closer to the center of the mass, because the this center is always closer to the 'L' shape.
See the link below:
docs.opencv.org/2.4/doc/tutorials/imgproc/shapedescriptors/moments/moments.html

centroid ellipse MSER OPENCV

I am working on an image registration method and I would like to work with region based feature detectors. As representative and because it is already implemented in opencv, i thought of MSER.
I know how to detect the MSER regions.MSER detector gives the MSER regions inside of a vector of points, a contour.I would like to retrieve the centroid of these contours. I could fit a ellipse on them, but then I don't as well how could I retrieve the centroid of these ellipses.
Does someone know if there is an already implemented function that could take care of this task? Or do i have to develop an algorithm?
The reason is that I would like to perform the point correspondence using this centroid points as interesting points.
Thanks
Iván
The centroid of the region can be computed by calculating the mean of all the x values and the mean of all the y values. The resulting (meanX, meanY) point is the region's centroid.

OpenCV - Find skewed rectangle

I want to draw a "bounding box" around a skewed rectangle. I thought I could use the cvMinAreaRect2() function but it only handles the rotation, see this image:
Is there any function to solve this?
If not, any ideas how to implement it?
Compute both MinAreaRect and ConvexHull. Then, for each of the four points found by MinAreaRect, find the corresponding nearest point in the convex hull.

Resources