Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize corrosion and expansion of OpenCV

Shulou Source: shulou.com Published: 2022-06-01 14:09:25 10月03日 Update

This article will explain in detail how to achieve corrosion and expansion of OpenCV. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Corrosion and expansion are also well used in image processing. We can change corrosion to minimum filtering and expansion to maximum filtering.

Or pick up our old DEMO?

Add corrosion and expansion to the Clistitem class

Then add these two projects to the loaded list

Then we add corrosion and expansion methods to the ImgDealUtil class

/ / corrosion and expansion

Public static void erodOrDilate (String command, Bitmap bmp) {

Boolean erode = command.equals (Clistitem.IMAGE_ERODECOMMAND)

Mat src = new Mat ()

Mat dst = new Mat ()

Utils.bitmapToMat (bmp, src)

/ / structure element, get the structure element

/ / Imgproc.MORPH_RECT sets our parameter to rectangle

/ / new Size defaults to the effect of 3: 3

/ / the final Point-1,-1 is still the central point.

Mat strElement = Imgproc.getStructuringElement (Imgproc.MORPH_RECT, new Size (3,3), new Point (- 1,-1))

If (erode) {

Imgproc.erode (src, dst, strElement, new Point (1,-1), 1)

} else {

Imgproc.dilate (src, dst, strElement, new Point (1,-1), 1)

}

Utils.matToBitmap (dst, bmp)

Src.release ()

Dst.release ()

StrElement.release ()

}

Finally, we add calls to these two methods to the button event of Mainactivity

Then we run the program to see how it works.

Original drawing

Corrosion-minimum filtration effect

This is the end of the article on "how to achieve corrosion and expansion of OpenCV". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Effects articles minimum two elements methods more structure or good practical maximum center point event content original image parameters image image processing buttons Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn OPPO Reno Redmi Linux