In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you the example analysis of changing pictures to grayscale in OpenCV Android, which is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
First, copy a picture logo.jpeg under the drawable of res.
Then add a button and a picture to the activity_main.xml interface
Return to the code file
First initialize the OpenCV
OpenCVLoader.initDebug ()
Then load the button and write the button event
Public void onClick (View view) {
BitmapFactory.Options options = new BitmapFactory.Options ()
/ / set the image read to argb8-bit
Options.inPreferredConfig = Bitmap.Config.ARGB_8888
/ / read the original resource picture
Bitmap bmp = BitmapFactory.decodeResource (getResources (), R.drawable.logo, options)
/ / create a Mat object scr as the source image resource dst as the target image resource
Mat src = new Mat ()
Mat dst = new Mat ()
/ / convert the loaded bmp image to the Mat object of scr
Utils.bitmapToMat (bmp, src)
/ / the Mat object of src is changed to grayscale and copied into the Mat object of dst
Imgproc.cvtColor (src, dst, Imgproc.COLOR_BayerGB2GRAY)
/ / then convert the Mat object of dst back into the bmp image
Utils.matToBitmap (dst, bmp)
/ / reassign a value to the picture
ImageView img = findViewById (R.id.img1)
Img.setImageBitmap (bmp)
}
Then we run directly in the virtual machine.
According to what I did in DEMO, I directly reported an error when I went to Imgproc.cvtColor. I haven't found any reason yet. It should be that the parameter of the new version in opencv is different, because I don't know about caching yet. Later, if you finish learning here, learn about the source code of C++ and analyze it, and then come back to deal with it here.
Later, I removed the 3.3.1 version, under the 2.4 version, so the packaged APK is no longer 80m, become 30m, much smaller, and so familiar with the opencv, and then their own useful packaging, reducing the size of the APK.
The above is the example analysis of changing pictures to grayscale in OpenCV Android. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.