Ask Your Question
1

convexityDefect for point or line

asked 2015-09-22 08:37:00 -0600

LBerger gravatar image

updated 2015-09-24 14:31:39 -0600

Hi,

When my program call convexityDefects with a contour which is a line or a point an exception is thrown at in convHull.cpp. I understand that for a line or a point there is no defect so may be it is better to send an empty vector<vec4i>.

Is it correct?

../../../modules/imgproc/src/convhull.cpp:279 error (-215) hpoints>2 in function cv::convexityDefects

image description

With image givenmy program is here

edit retag flag offensive close merge delete

Comments

What is the exception?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-09-22 08:44:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-09-22 10:00:41 -0600

thdrksdfthmn gravatar image

There is no convexity to be computed if the contour has not at least 3 points (so it may be a polygon)... I consider that the function is ok, you should filter those contours that may not be polygons

edit flag offensive delete link more

Comments

Yes but for a convex shape there is no convexity defect result is an empty vector<vec4i>. I think there is no need to throw an exception if I follow this

LBerger gravatar imageLBerger ( 2015-09-22 10:17:37 -0600 )edit

As you see, the problem is in convhull. A hull cannot be computed for a non-polygon contour, that is why I said that it is correct and you shall do the filter of 1 ad 2 points contours. The function is computing first the convex hull and then it determines the defects, so an exception is thrown in case of non-polygon contour

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-09-22 10:53:29 -0600 )edit

Problem is for contour 6 which have four points : point 0 (65,39), point 1(66,39), point 2 (67,39), point 3 (66,39) ConvexHull is 2 and 0.

No for contours 1 it'sonly one point in (258,71) convexHull is only point 0. Here there is no exception. it is processed at this line.

It seems so that problem occurs when there is a contour with 4 points and only two points in convex Hull

LBerger gravatar imageLBerger ( 2015-09-22 13:57:04 -0600 )edit

The problem seems to be in the hull, the 4 points contour cannot have 2 points convexHull. Are you sure that it is the right hull? IMHO the hull shall has at least 3 points. Anyway, have you tried to do some erode+dilate for removing the small contours?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-09-23 02:48:36 -0600 )edit

With image given in questions my program is here

LBerger gravatar imageLBerger ( 2015-09-23 07:10:28 -0600 )edit

I think it's a bug when contour is a line Then convexHull is a line with two points and that's good and there is no convexity defect.

I don't want to use erode because it's an image processing program and user will do what he wants.

LBerger gravatar imageLBerger ( 2015-09-24 14:30:50 -0600 )edit

There is no polygon with less than 3 corners... as wikipedia says it, too, the monogon and digon are "Not generally recognised as a polygon". So you should filter those out. On the other hand I had not time to test your code, probably I'll do it this weekend.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-09-25 02:25:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-22 08:37:00 -0600

Seen: 1,072 times

Last updated: Sep 24 '15