Ask Your Question
1

Rotated ellipse as structuring element.

asked 2012-12-23 11:25:12 -0600

kostek gravatar image

Hi, Is there any way to apply rotated ellipse as structuring element in OpenCV? I need this to perform erode/dilate.

Thank for your help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-12-23 12:26:44 -0600

updated 2012-12-23 12:29:32 -0600

In the first you have to create a image with depth = IPL_DEPTH_32S then you can use the cvCreateStructuringElementEx with CV_SHAPE_CUSTOM flag.

IplImage* rectImg = cvCreateImage(cvSize(200,200),8,1);
cvZero(rectImg);
cvRectangle(rectImg,cvPoint(50,50),cvPoint(150,150),cvScalarAll(255),-1);

IplImage* rotateEllipseImg = cvCreateImage(cvSize(21,21),IPL_DEPTH_32S,1);
cvZero(rotateEllipseImg);
cvEllipse(rotateEllipseImg,cvPoint(10,10),cvSize(10,5),45,0,360,cvScalarAll(255),-1);

IplImage* viewKernel = cvCreateImage(cvGetSize(rotateEllipseImg),8,1);
cvNormalize(rotateEllipseImg,viewKernel,0,255,CV_MINMAX);
cvShowImage("kernel",viewKernel);
cvReleaseImage(&viewKernel);

IplConvKernel* kernel = cvCreateStructuringElementEx(21,21,10,10,CV_SHAPE_CUSTOM,(int*)rotateEllipseImg->imageData);

cvShowImage("before",rectImg);
cvDilate(rectImg,rectImg,kernel,2);
cvShowImage("after",rectImg);

cvWaitKey(0);
cvReleaseImage(&rectImg);
cvReleaseImage(&rotateEllipseImg);
cvReleaseStructuringElement(&kernel);

image description

edit flag offensive delete link more

Comments

Thanks a lot!

kostek gravatar imagekostek ( 2012-12-24 05:39:35 -0600 )edit

Question Tools

Stats

Asked: 2012-12-23 11:25:12 -0600

Seen: 855 times

Last updated: Dec 23 '12