1 | initial version |
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);
2 | No.2 Revision |
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);