In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "Java how to achieve picture comparison algorithm", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Java how to achieve picture comparison algorithm" article.
The effect is as follows:
Recognition result:
The main code is as follows:
Import javax.imageio.*;import java.awt.image.*;import java.awt.*;import java.io.*; public class PhotoDigest {public static void main (String [] args) throws Exception {float percent = compare (getData ("/ Users/sun/Downloads/1.jpg"), getData ("/ Users/sun/Downloads/3.jpg")); if (percent = = 0) {System.out.println ("cannot compare") } else {System.out.println ("similarity between the two pictures is:" + percent + "%");}} public static int [] getData (String name) {try {BufferedImage img = ImageIO.read (new File (name)); BufferedImage slt = new BufferedImage (100,100, BufferedImage.TYPE_INT_RGB) Slt.getGraphics () .drawImage (img, 0,0,100,100, null); / / ImageIO.write (slt, "jpeg", new File ("slt.jpg")); int [] data = new int [256]; for (int x = 0; x < slt.getWidth (); xbirthday +) {for (int y = 0; y < slt.getHeight () ) {int rgb = slt.getRGB (x, y); Color myColor = new Color (rgb); int r = myColor.getRed (); int g = myColor.getGreen (); int b = myColor.getBlue (); data [(r + g + b) / 3] + + }} / / data is the so-called concept of histogram in graphics return data;} catch (Exception exception) {System.out.println ("there is a file not found, please check whether the file exists or the path is correct"); return null }} public static float compare (int [] s, int [] t) {try {float result = 0F; for (int I = 0; I < 256; iTunes +) {int abs = Math.abs (s [I]-t [I]); int max = Math.max (s [I], t [I]) Result + = (1-(float) abs / (max = = 0? 1: max);} return (result / 256) * 100;} catch (Exception exception) {return 0 } the above is about the content of this article on "how to realize the picture comparison algorithm in Java". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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.