How to smooth the contour using Python - python

I am working on a detection problem and I have found the mask of the object using cv2.findContours(). However, the found contour has a lot of noise and isn't smooth while the requirement is that it has to be smooth so we can use that smooth contour for our next step.
The obtained mask
The curve I want (the red line)
I have tried cv2.approxPolyDP() to reduce the noise but it is no longer a curve. I was asked to find a smooth curve.
The curve after using cv2.approxPolyDP()
Is there any way to do it?

Related

How to get the area of a contour on a 3D surface from a single photo?

I'm beginning to work on a project with OpenCV (in python), and I'm trying to figure out the best way to tackle the problem I'm facing. I'm trying to get the area of an item in an image...but the surface area I'm looking for is on a 3D object.
So I found this while searching for calculating the area of a contour, but as you can see, this is only for a 2D object. For example, how could I find the area of the red question marks on the sphere in this image? Or the size of the rash on this baby's face (which is most certainly not 2-dimensional)? Is there a way to find the depth of the surface in the image, then use the high color gradient difference to find contours and calculate the difference based on the depths?
I found this deep learning paper (and associated PyTorch library), but was wondering if there was another way that I was missing...
Thanks to all for any ideas / replies.

OpenCV - How to get the tangent of a polygonal curve

I'm trying to get the tangent of a polygonal curve I got using approxPolyDP(), I have tried Hough lines and some mathematical formulas for gradient but none of them worked.
I want to get the tangent in the red marks in the image.

How to determine most curvature points of a graph in python

I have a figure that I get contour lines from a picture of face use by opencv (image below). I need to determine most curvature points of this contour in python (in the image, I need to define the red dots on right of the red line). How can I do it ?
Just find contour and compute curvature then find maximums: curvature
This article also may be useful: article

How to smooth a contour using opencv in python?

I am trying to find the contours of human hands for gesture recognition.After some pre processing and thresholding, I am extracting the contour. The contours I am getting are as below,
I want to smooth out the contour. I tried using scipy.ndimage.zoom but it seems to be changing the dimensions of the input numpy array. How can I smooth out the contour keeping the shape of the input array the same?

Draw a curve joining a set of points in opencv python

I have a set of points extracted from an image. I need to join these points to from a smooth curve. After drawing the curve on the image, I need to find the tangent to the curve and represent it on the image. I looked at cv2.approxPolyDP but it already requires a curve??
You can build polyline, if order of points is defined. Then it is possible to simplify this polyline with Douglas-Peucker algorithm (if number of points is too large). Then you can construct some kind of spline interpolation to create smooth curve.
If your question is related to the points being extracted in random order, the tool you need is probably the so called 2D alpha-shape. It is a generalization of the convex hull and will let you trace the "outline" of your set of points, and from there perform interpolation.

Categories