how to turn contours into vectors?
Hi
I have a simple irregular shape. I have a broken edges of this shape in black and white after pre-processing it. I extracted the contours from this image.
I want to convert this contour to a simple vector(least number of points with which I can reconstruct the edges again).
Any help as to how I can do this?????
Example: Image of a stone
This is the edge extracted image I have got after pre processing
Here's the code I'm using to access the contours
ret, thresh = cv2.threshold(dnoise,127,255,0)
dnoise, contours, hieararchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
print(contours)
for ar_i, arr in enumerate(contours):
for row_i, row in enumerate(arr):
if (row_i==0):
for el in row:
print("\n",format(el))
I don't want to use inbuilt ellipse function in cv!
Why do you mean by vector ? math vector ? C++ vector (contour is already vector<point>?
I want to find the best fit points that can describe the shape with minimum number of points. From all the detected contours. I am using python here, not C++.
I don't know python but may be approxPolyDP can help you
How about this?
Storing the first element of each and every contour that is found in the image. Connecting the stored elements.
see the documentation
@Santhosh1 what both @LBerger and @sturkmen actually want to point out is that a contour is already in a vector format. However, your question is soo poorly formulated, I think they miss the point. Probably you have some black and white edges indicating a contour, but not the contour itself right? Update your question, add sample images, a line of code, ... and people will help you much more concrete.
i would like to help but i did not understand what do you want to do
In the example above we have got the outer edges of the stone.
At pixel level even these edges which look thin to our eye would be a collection of more than a single pixel.
I want to select as much less pixels(points) as possible in this image, so that I can get a rough shape of the image.
Blur original image
please post the code you used so far. let's solve the point you stuck.