Rotated ellipse as structuring element.
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.
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.
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);
Asked: 2012-12-23 11:25:12 -0600
Seen: 836 times
Last updated: Dec 23 '12