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;
            }


  • 相关阅读:
    [bzoj1911][Apio2010特别行动队] (动态规划+斜率优化)
    [bzoj1597][usaco2008 mar]土地购买 (动态规划+斜率优化)
    [bzoj1901][zoj2112][Dynamic Rankings] (整体二分+树状数组 or 动态开点线段树 or 主席树)
    整体二分初步
    bzoj[3238][ahoi差异]
    概率dp学习
    poj[2104]K-th Number
    hdu[1711]number sequence
    hdu[2222]keywords search
    poj[1187][Noi 01]陨石的秘密
  • 原文地址:https://www.cnblogs.com/afxcn/p/2067539.html
Copyright © 2011-2022 走看看