Ask Your Question
3

How to use the function ‘cvCreateStructuringElementEx ()’?

asked 2012-12-08 23:00:30 -0600

isaacenrique gravatar image

Regards

I think in my previous post, “Create a structuring element of 3 * 3”, I do not clearly established what the problem was; maybe not well understood what I meant.

The problem is: how to use the function

cvCreateStructuringElementEx()

to create a structuring element of 3 * 3 with origin at the center (obviously a solid rectangular structuring element).

As I understand it, this is the structuring element that is created by default when none is given … Right?

So the question is: what parameters should I pass to the function?

I tested with the following:

(case 1) cvCreateStructuringElementEx (3, 3, 1, 1, CV_SHAPE_RECT);

and

(case 2) cvCreateStructuringElementEx (3, 3, -1, -1, CV_SHAPE_RECT);

In the first case I got an SE is not the one I’m waiting (I think), and that when used to dilate an image, as follows:

cvDilate (entrada_gris, dilatacion2, ee, iterations);

obtain a resulting image that is different from that obtained with:

cvDilate (entrada_gris, dilatacion1, NULL, iterations);

I think that the results should be the same (ie dilatacion1 = dilatacion2), but it is not.

In case 1, I conclude that one of the two structural elements (either ‘ee’ or the structuring element is created when passing NULL to function) is not a rectangular structuring element of 3 * 3 with origin at the center … Right?

In the second case an error is generated at runtime.

Thanks in advance to anyone who can provide some help regarding this issue.

By the way, I’m working with OpenCV 2.2.0 and 1.2.1 QtSDK under Windows 7 64-bit

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2012-12-11 07:42:39 -0600

Michael Burdinov gravatar image

updated 2012-12-12 02:07:05 -0600

It seems like a mix of bugs (although they may come from single source).

1) Online documentation states that (3,3,-1,-1,CV_SHAPE_RECT) should be used, but in experiments I just did, I saw that (3,3,1,1,CV_SHAPE_RECT) gives correct result, and (3,3,-1,-1,CV_SHAPE_RECT) causes run time error. Sorry for my previous answer about this issue.

2) I receive even weirder results when I use C++ interface (i.e. getStructuringElement function). Anchor point I provide to it is ignored, i.e. changing anchor point has no influence on result. And when I provide anchor points to dilate function, I receive same results for both (1,1) and (-1,-1) anchor points... But when I use (0,0) as anchor the result is indeed shifted...

3) It seems that you meet an old bug that was present in OpenCV 1.0. When morphological function (like dilate or erode) is used, and the value of 'iterations' argument is bigger than 1, some shift of structuring element happens. I was sure that this issue was resolved years ago. And it indeed was resolved for default structuring element. But as I see now the problem still persists when user defined SE is used. I checked it both in C and C++ interfaces, just in case.

I am using OpenCV 2.4.2 while you are using 2.2.0, but if the problem exists in my version I guess it should be the same problem in yours.

As a temporary workaround for this bug until it will be fixed, you can run dilate function inside 'for loop', with 'iterations' argument set to 1. Reduces speed, but at least the result is correct.

Please report this issue in bug tracker.

On a side note, it is good to use last version of OpenCV, because each release had considerable amount of bug fixes (although not all the bugs are found and fixed yet, as you just experienced). And it is good to use C++ interface if possible (code is cleaner, automatic resource management, and so on).

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-12-08 23:00:30 -0600

Seen: 6,828 times

Last updated: Dec 12 '12