In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to achieve the mosaic effect of JavaCV photos, I hope you will learn something after reading this article, let's discuss it together!
Preparatory work
Let's introduce the dependency library of JavaCV first.
Org.bytedeco javacv-platform 1.5.6
If introduced in this way, everything contained in javacv will be introduced. You can do this when you test and use it at ordinary times. But in a real project, it still needs to be streamlined.
Besides, we have prepared a picture.
Code implementation
Read a file
Val path = "path/to/img/" val img = opencv_imgcodecs.imread (path + "meinv.jpeg")
Get the pixel width and height of the original image, and then scale the pixel ratio.
Val size = img.size () val height = size.height () val width = size.width () val pixelSize = 10 val newWidth = width / pixelSizeval newHeight = height / pixelSize
According to the set pixel ratio, the original image is reduced, and then magnified two times of resize operation. In this way, the pixel image processing is completed.
Val imgTmp: Mat? = null opencv_imgproc.resize (img, imgTmp, Size (newWidth, newHeight), 0.0,0.0, opencv_imgproc.INTER_NEAREST) opencv_imgproc.resize (img, imgTmp, Size (width, height), 0.0,0.0, opencv_imgproc.INTER_NEAREST)
Let's take a look at the image effect after processing.
The effect looks OK, the picture color is single, the picture size is slightly smaller, the effect will be much better.
Complete code import org.bytedeco.opencv.global.opencv_highguiimport org.bytedeco.opencv.global.opencv_imgcodecsimport org.bytedeco.opencv.global.opencv_imgprocimport org.bytedeco.opencv.opencv_core.Matimport org.bytedeco.opencv.opencv_core.Sizefun main (args: Array) {val path = "path/to/img/" val img = opencv_imgcodecs.imread (path + "meinv.jpeg") val size = img.size () val height = size.height () Val width = size.width () val pixelSize = 10 val newWidth = width / pixelSizeval newHeight = height / pixelSizeval imgTmp: Mat? = null opencv_imgproc.resize (img ImgTmp, Size (newWidth, newHeight), 0.0,0.0, opencv_imgproc.INTER_NEAREST) opencv_imgproc.resize (img, imgTmp, Size (width, height), 0.0,0.0, opencv_imgproc.INTER_NEAREST) opencv_highgui.imshow ("meinv", img) Opencv_highgui.waitKey (0)} after reading this article, I believe you have a certain understanding of "how JavaCV achieves photo mosaic effect". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.