Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shapes detection - contour approximation with OpenCV

I'm writing small application for shape detections. What I need to do in a first place is to find the most significant shape on an image. I started from some preprocessing including converting image to grayscale, thresholding and edge detection. Image before and after these operations is presented below

Before

enter image description here

After

enter image description here

So as You can see the main shape is visible (however it is a bit scattered) and there are also some noises (small trees etc). What I need to do is to extract somehow only the most significant shape (the biggest one) - in this case it is a tower. What I wanted to do is use contour finding function in opencv and then somehow aproximate found conturs with polygon. Then I would (somehow) calculate area of countours and select only the biggest one. So far I manged (only) to find contours using

cvFindContours(crated,g_storage,&contours);

I know that there is a

cvApproxPoly

function , however I am not able to get any usefull information for the result of this function. Could somebody tell me if it is possible to calculate area of contour or to approximate the contur with polygon. Maybe You have a better idea how to extract only the most significant shape ?

like image 973
inferno Avatar asked Jun 12 '11 13:06

inferno


People also ask

How does OpenCV detect contour?

Use the findContours() function to detect the contours in the image. Draw Contours on the Original RGB Image.

How do you approximate a contour?

Contour approximation, which uses the Ramer–Douglas–Peucker (RDP) algorithm, aims to simplify a polyline by reducing its vertices given a threshold value. In layman terms, we take a curve and reduce its number of vertices while retaining the bulk of its shape.


1 Answers

You don't have to do edge detection here. Just threshold to a binary image and then find blobs (cvFindContours) on that. You can use cvContourArea on each returned CvSeq to find its area.

like image 80
damian Avatar answered Oct 01 '22 16:10

damian