zoukankan      html  css  js  c++  java
  • 京东商城图片价格识别

        因项目需要,花了点时间做了个小程序来演示京东商城的图片价格识别,初步试用效果还不错。

        先上个图:

    用了个最简单的算法:

    /// <summary>
            
    /// 图片解码
            
    /// </summary>
            
    /// <param name="srcBitmap">0-9和.的源图像</param>
            
    /// <param name="distBitmap">目标图像</param>
            
    /// <returns></returns>
            public static string DecodeGrayBitmap(IList<Bitmap> srcBitmap, Bitmap[] distBitmap)
            {
                StringBuilder sb 
    = new StringBuilder();

                
    foreach (Bitmap dist in distBitmap)
                {
                    
    int val = 0;
                    
    double max = 0;

                    
    for (int pos = 0; pos < srcBitmap.Count; pos++)
                    {
                        
    double n = ClacMatchRate(srcBitmap[pos], dist);

                        
    if (n > max)
                        {
                            max 
    = n;
                            val 
    = pos;
                        }

                        
    if (max > 0.9)
                            
    break;
                    }

                    
    if (val == 10)
                    {
                        sb.Append(
    '.');
                    }
                    
    else
                    {
                        sb.Append(val);
                    }
                }

                
    return sb.ToString();
            }

            
    public static double ClacMatchRate(Bitmap src, Bitmap dist)
            {
                
    double black = 0;
                
    double match = 0;

                
    int w = src.Width < dist.Width ? src.Width : dist.Width, h = src.Height < dist.Height ? src.Height : dist.Height;

                
    for (int x = 0; x < w; x++)
                {
                    
    for (int y = 0; y < h; y++)
                    {
                        
    int sc = PixelGrayValue(src.GetPixel(x, y));
                        
    int dc = PixelGrayValue(dist.GetPixel(x, y));

                        
    if (sc == 0 || dc == 0)
                        {
                            black
    ++;

                            
    if (sc == dc)
                                match
    ++;
                        }
                    }
                }

                
    return match / black;
            }


  • 相关阅读:
    Node 文件上传,ZIP
    jquery实现前台倒计时。应用下单24小时后自动取消该订单
    solr 4.4添加索引是新手容易遇到的问题
    solr 4.6的安装配置
    java.lang.OutOfMemoryError: PermGen space
    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
    mybatis代码生成(generator工具生成代码)
    再次熟悉jdbc连接mysql
    魔方阵,奇数阵。输入一个奇数,产生一个魔方阵
    错误,这个如何解决呢?内存溢出的问提。把JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m 还是不行
  • 原文地址:https://www.cnblogs.com/afxcn/p/2067539.html
Copyright © 2011-2022 走看看