OpenCV Source Learning: getstructuringelement function;

Source: Internet
Author: User

The Getstructuringelement function is attributed to morphology, and the structure of the specified size and shape can be established.

Prototype:

/** @brief Returns A structuring element of the specified size and shape for morphological operations. The function constructs and returns the structuring element that can is further passed to CV::ERODE,CV::d ilate or Cv::morp Hologyex. But you can also construct a arbitrary binary mask yourself and use it asthe structuring element. @param shape Element sha PE that could is one of Cv::morphshapes@param ksize Size of the structuring element. @param anchor anchor position within T He element. The default value \f$ ( -1,-1) \f$ means that theanchor are at the center. Note that only the shape of a cross-shaped element depends on the anchorposition. In and cases the anchor just regulates how much the result of the morphologicaloperation is shifted. */cv_exports_w Mat getstructuringelement (intShape, Size ksize, point anchor = Point (-1,-1));

Source Code Analysis:

Cv::mat Cv::getstructuringelement (intshape, Size ksize, point anchor) {    intI, J; intR =0, C =0; DoubleINV_R2 =0; Cv_assert (Shape= = Morph_rect | | Shape = = Morph_cross | | Shape = =morph_ellipse); Currently supports three shapes of cell creation: rectangular, cross-shaped, oval; Anchor=Normalizeanchor (anchor, ksize);    When the default is -1,-1, calculate anchor; if(Ksize = = Size (1,1))//When a given size of 1, 1 o'clock, indicates a point, which can be represented by a rectangle; shape=Morph_rect; if(Shape = =morph_ellipse)//ellipse; {R= ksize.height/2; C= ksize.width/2; INV_R2= r?1./((Double) r*r):0;    } Mat Elem (Ksize, cv_8u);  for(i =0; i < ksize.height; i++)//For each row, calculate the range of 0,1; {Uchar* ptr =elem.ptr (i); intJ1 =0, J2 =0; if(Shape = = Morph_rect | | (Shape = = Morph_cross && i = =anchor.y))//Rectangle, or cross y anchor point when J2 is ksize.width; J2=Ksize.width; Else if(Shape = =morph_cross) J1= anchor.x, J2 = J1 +1; else//ellipse;        {            intDY = i-R; if(Std::abs (DY) <=r) {intDX = saturate_cast<int> (C*STD::SQRT (r*r-dy*dy) *inv_r2)); Calculate the offset of x; J1= Std::max (C-DX,0 ); J2= Std::min (c + dx +1, Ksize.width); }        }         for(j =0; J < J1; J + +)//From these three for can be seen, (0,j1) between 0, (J1, J2) between 1, (J2, ksize.width) between 0; PTR[J]=0;  for(; J < J2; J + +) Ptr[j]=1;  for(; J < Ksize.width; J + +) Ptr[j]=0; }    returnElem;}

OpenCV Source Learning: getstructuringelement function;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.